I'm new working with MeteorJS dev an app, this is a problem when I'm making the collection of some item in an quick inventory app.
Here is the error:
/home/operador/.meteor/packages/meteor-tool/.1.1.10.1kpywhr++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
throw(ex);
^
Error: Invalid definition for active field.
at packages/aldeed_simple-schema/packages/aldeed_simple-schema.js:1328:1
at Function._.each._.forEach (packages/underscore/underscore.js:113:1)
at [object Object].SimpleSchema (packages/aldeed_simple-schema/packages/aldeed_simple-schema.js:1325:1)
at collections/assets.js:16:16
at /home/operador/fijos/.meteor/local/build/programs/server/app/collections/assets.js:64:4
at /home/operador/fijos/.meteor/local/build/programs/server/boot.js:242:10
at Array.forEach (native)
at Function._.each._.forEach (/home/operador/.meteor/packages/meteor-tool/.1.1.10.1kpywhr++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
at /home/operador/fijos/.meteor/local/build/programs/server/boot.js:137:5
Exited with code: 8
Your application is crashing. Waiting for file change.
And this is the assets.js:
Assets = new Mongo.Collection('assets')
Assets.allow({
insert: function(userId, userLvl, doc) {
return !!userId;
}
});
Brands = new SimpleSchema({
name: {
type: String,
label: "Brand"
}
});
Assetsschema = new SimpleSchema({
item: {
type: String,
label: "item"
},
year: {
type: Date,
label: "year"
},
model: {
type: String,
label: "model"
},
serialNumber: {
type: String,
label: "serialNumber"
},
brand: {
type: [Brands]
},
adquarance: {
type: Date,
label: "adquaranceDate"
},
codebar: {
type: String,
label: "codebar"
},
qrcode: {
type: String,
label: "QRcode"
},
active: {
type: Boolean,
label: "active",
autoValue: true
}
});
IDK how to fix the problem, I've tried to change the name of the schema but that gave me the same results.
This is my package list:
kadira:flow-router
kadira:blaze-layout
erasaur:meteor-lodash
fortawesome:fontawesome
spiderable
fastclick
raix:handlebar-helpers
aldeed:collection2
aldeed:autoform
accounts-ui
accounts-password
matb33:bootstrap-glyphicons
zimme:active-route
gwendall:auth-client-callbacks
meteortoys:allthings
datariot:ganalytics
bootswatch:paper
numtel:mysql
hitchcott:qr-scanner
The option autoValue allows you to specify a function. As a consequence, your Schema should be structured as follows:
Assetsschema = new SimpleSchema({
item: {
type: String,
label: "item"
},
year: {
type: Date,
label: "year"
},
model: {
type: String,
label: "model"
},
serialNumber: {
type: String,
label: "serialNumber"
},
brand: {
type: [Brands]
},
adquarance: {
type: Date,
label: "adquaranceDate"
},
codebar: {
type: String,
label: "codebar"
},
qrcode: {
type: String,
label: "QRcode"
},
active: {
type: Boolean,
label: "active",
autoValue: function () {
return true;
}
}
});
Related
I am using the mongoose updateMany() method and I also want to keep it a part of transaction. The documentation shows the example of save() where I can do something like Model.save({session: mySession}) but don't really know how to use it with for example Model.updateMany()
UPDATE:
For example I have two models called SubDomain and Service and they look like this respectively:
SUB-DOMAIN
{
name: {
type: String,
required: true,
},
url: {
type: String,
required: true,
unique: true,
},
services: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Service",
},
],
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
},
}
SERVICE:
{
name: {
type: String,
required: true,
},
description: {
type: String,
required: true,
},
price: { type: Number },
tags: { type: Array },
packages: [
{
name: { type: String, required: true },
description: { type: String, required: true },
price: { type: Number, required: true },
},
],
map: { type: String },
isHidden: {
type: Boolean,
required: true,
default: false,
},
sortingOrder: { type: Number },
isForDomain: { type: Boolean, required: false, default: false },
isForSubDomain: { type: Boolean, required: false, default: false },
subDomains: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "SubDomain",
},
],
}
Now the main field here is the services field in SubDomain and subDomains field in Service.
The complicated part😅:
Whenever the user wants to create new service, I want to $push that service's _id into the array of services of all the subDomains inside that new service
And for that, I am using the updateMany() like this:
const sess = await mongoose.startSession();
sess.startTransaction();
const newService = new Service({
_id: mongoose.Types.ObjectId(),
subDomains: req.body.subDomains
...foo
})
await SubDomain.updateMany(
{ _id: { $in: req.body.subDomains } },
{ $push: { services: newService._id } }
);
The problem starts here, of course I can do:
newService.save({session: sess})
but how do I keep my SubDomain's updateMany in the same transaction (i.e sess)
I know my example is difficult to wrap your head around but I have tried to pick a simplest example rather than copying the exact same code which would have been a lot more difficult
my schema like this
customer : {
type: Schema.Types.ObjectId,
ref: 'Customer'
},
doctor: {
type: Schema.Types.ObjectId,
ref: 'Doctor'
},
return_patient : {
type: Boolean,
default: false
},
consultation: {
type: Number, //1: Phone, 2: Video
required: true
},
fee: {
type: Number
},
payment: {
type: Schema.Types.Mixed
},
schedule_date: {
type: Date
},
schedule_time: {
from: {
type: String
},
to: {
type: String
}
},
now i want check doctor availablity
from req.query
localhost:9000/api/appointment/doctor-available?doctor=5e83704aadca4064368ff24f&date=2020-04-01&from=5.30&to=6.00
match the table and query if data came means doctor is not available otherwise
doctor available
When using simpl-schema I am getting the following error:
SimpleSchema is not a constructor
I have already added
aldeed:autoform
aldeed:collection2#3.0.0
"simpl-schema": "^1.4.3"
My code:
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
export const Books = new Mongo.Collection("books");
const Book = new SimpleSchema({
title: {
type: String,
label: "Title",
max: 200
},
author: {
type: String,
label: "Author"
},
copies: {
type: SimpleSchema.Integer,
label: "Number of copies",
min: 0
},
lastCheckedOut: {
type: Date,
label: "Last date this book was checked out",
optional: true
},
summary: {
type: String,
label: "Brief summary",
optional: true,
max: 1000,
optional: true
}
});
Books.attachSchema(Book);
What's causing it and how can I fix it?
Trying to create an event that changes a String called status in my NetworkApp collection.
Event:
Template.app_detail.events({
'click .accept': function (e, t) {
console.log("Accept");
NetworkApp.update(this._id, {$set:{
status: "Accepted"
}});
},
'click .reject': function (e, t) {
console.log("Reject");
NetworkApp.update(this._id, {$set:{
status: "Rejected"
}});
}
})
It updates the last time the application was modified but not the status. No errors appear in the console but it does log Accepted or Rejected so the code can connect to the db and the helper is being triggered by the buttons. Any help is appreciated!~
Simple Schema:
NetworkAppSchema = new SimpleSchema({
ign: {
type: String,
label: "IGN"
},
discordName: {
type: String,
label: "Discord Name"
},
memberlength: {
type: String,
label: "How long have you been a member at Digital Hazards?"
},
languageKnown: {
type: String,
label: "What languages do you know?",
autoform: {
type: 'textarea'
}
},
whyyou: {
type: String,
label: "Why do you want to join the Network staff?",
autoform: {
type: 'textarea'
}
},
applicant: {
type: String,
label: "Applicant",
autoValue: function() {
return Meteor.userId();
},
autoform: {
type: "hidden"
}
},
createdAt: {
type: Date,
label: "Applied At",
autoValue: function() {
return new Date();
},
autoform: {
type: "hidden"
}
},
status: {
type: String,
label: "Status",
autoValue: function() {
return "Pending";
},
autoform: {
type: "hidden",
}
}
});
autoValue does not mean initial value: your autoValue functions are running every time.
For createdAt for example you should have:
createdAt: {
type: Date,
denyUpdate: true,
autoValue() {
if (this.isInsert) return new Date();
},
},
this will avoid the createdAt ever changing after insert.
Similarly for status:
status: {
type: String,
label: "Status",
autoValue() {
if (this.isInsert) return "Pending";
},
autoform: {
type: "hidden",
}
}
My model definition looks like this:
//api/models/Table.js
module.exports = {
tableName: 'table',
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
id: {
type: 'integer',
autoIncrement: true,
primaryKey: true,
size: 11
},
title1: {
type: 'string',
index: true,
size: 255
},
title2: {
type: 'string',
size: 255
},
title2: {
type: 'string',
size: 255
},
countries: { //Countries nationalities
model: 'hg_laender'
},
year: {
type: 'string',
size: 4
},
relased: { //released
type: 'string',
enum: ['true', 'false']
},
createdOn: { //Created on
type: 'datetime'
},
changedOn: { // Changed on
type: 'datetime'
},
documents: { //Document type
collection: 'documents',
via: 'table',
dominant: true
},
creator: { //Creator
collection: 'creator',
via: 'table',
dominant: true
},
kanton: { // Canton
collection: 'kanton',
via: 'table',
dominant: true
},
language: {
collection: 'language',
via: 'table',
dominant: true
}
}
};
The code generating the error is the following
Table.find()
.exec((err, tables) => {
if(err) {
sails.log.error('first error', err);
}
sails.log.debug(tables[0]); //The record is loaded correctly
tables[0].save((err, model) => {
if(err) {
sails.log.error('second error', err);
}
});
});
I get the following error message:
error: second error Error (E_UNKNOWN) :: Encountered an unexpected error
at new WLError (/home/xxx/node_modules/waterline/lib/waterline/error/WLError.js:25:15)
at /home/xxx/node_modules/waterline/lib/waterline/model/lib/defaultMethods/save.js:196:17
at /home/xxx/node_modules/async/lib/async.js:52:16
at /home/xxx/node_modules/async/lib/async.js:550:17
at /home/xxx/node_modules/async/lib/async.js:544:17
at _arrayEach (/home/xxx/node_modules/async/lib/async.js:85:13)
at Immediate.taskComplete (/home/xxx/node_modules/async/lib/async.js:543:13)
at processImmediate [as _immediateCallback] (timers.js:383:17)
If a use the create() method it works. t actually save the record on the database. But if I try to update it, it doesn't work.
Any idea of what I'm doing wrong?
Additional info:
- sails.js version: 0.12.8
Seems like there was a problem if a manually specify the id of the model.
Now i changed the model like below and it works. Btw I don't know why specifing the id will not work. Also it' doesn't throw any error when creating a model..
//api/models/Table.js
module.exports = {
tableName: 'table',
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
//id: {
// type: 'integer',
// autoIncrement: true,
// primaryKey: true,
// size: 11
//},
title1: {
type: 'string',
index: true,
size: 255
},
title2: {
type: 'string',
size: 255
},
title2: {
type: 'string',
size: 255
},
countries: { //Countries nationalities
model: 'hg_laender'
},
year: {
type: 'string',
size: 4
},
relased: { //released
type: 'string',
enum: ['true', 'false']
},
createdOn: { //Created on
type: 'datetime'
},
changedOn: { // Changed on
type: 'datetime'
},
documents: { //Document type
collection: 'documents',
via: 'table',
dominant: true
},
creator: { //Creator
collection: 'creator',
via: 'table',
dominant: true
},
kanton: { // Canton
collection: 'kanton',
via: 'table',
dominant: true
},
language: {
collection: 'language',
via: 'table',
dominant: true
}
}
};
I too faced this Issue while using Sails with mongo. I fixed this by changing "id" attribute to some other attribute, say "Id". While creating a record, an "id" attribute is created itself that holds mongo ObjectId. May be this could be the reason for not allowing two id attribute at the same time resulting into error.