问题
trying to read between StackOverflow and the documentation of meteor-simple-schema but can't find a solution. I'trying to insert data in the Meteor.users collection through a form. But keep getting an error:
Uncaught Error: When the modifier option is true, validation object must have at least one operator
checkModifier @ simple-schema-validation.js:271doValidation1 @ simple-schema-validation.js:321doValidation @ simple-schema-context.js:9simpleSchemaValidationContextValidate @ simple-schema-context.js:44doValidate @ collection2.js:317_.each.Mongo.Collection.(anonymous function) @ collection2.js:154(anonymous function) @ VM47084:2InjectedScript._evaluateOn @ VM47083:883InjectedScript._evaluateAndWrap @ VM47083:816InjectedScript.evaluate @ VM47083:682
Any clue?
if (Meteor.isClient) {
Template.artistform.events({
'submit': function (event) {
event.preventDefault(); //prevent page refresh
var currentUserId = this.userId;
form={firstName:firstname.value, lastName:lastname.value};
Meteor.users.update({_id:currentUserId}, {$set:form});
}
});
}
And the Schema
Schema = {};
Schema.UserCountry = new SimpleSchema({
name: {
type: String,
optional: true
},
code: {
type: String,
regEx: /^[A-Z]{2}$/,
optional:true
}
});
Schema.UserProfile = new SimpleSchema({
firstName: {
type: String,
regEx: /^[a-zA-Z-]{2,25}$/,
optional: true
},
lastName: {
type: String,
regEx: /^[a-zA-Z]{2,25}$/,
optional: true
},
birthday: {
type: Date,
optional: true
},
category : {
type: String,
allowedValues: ['Painting', 'Music','Other'],
optional: true
},
website: {
type: String,
regEx: SimpleSchema.RegEx.Url,
optional: true
},
bio: {
type: String,
optional: true
},
country: {
type: Schema.UserCountry,
optional: true
}
});
Schema.User = new SimpleSchema({
email: {
type: String,
optional: true
},
"email.verified": {
type: Boolean,
optional: true
},
profile: {
type: Schema.UserProfile,
optional: true
},
createdAt: {
type: Date,
autoValue: function() {
if (this.isInsert) {
return new Date();
} else if (this.isUpsert) {
return {$setOnInsert: new Date()};
} else {
this.unset();
}
}
}
});
Meteor.users.attachSchema(Schema.User);
Many thanks.
回答1:
Try this schema
Schema.User = new SimpleSchema({
email: {
type: Object
},
'email.address': {
type: String,
optional: true
},
"email.verified": {
type: Boolean,
optional: true
},
profile: {
type: Schema.UserProfile,
optional: true
},
createdAt: {
type: Date,
autoValue: function() {
if (this.isInsert) {
return new Date();
} else if (this.isUpsert) {
return {$setOnInsert: new Date()};
} else {
this.unset();
}
}
}
});
Btw if you are using account-password then this schema won't work as that package expect emails to be stored in a certain way.
来源:https://stackoverflow.com/questions/30032315/uncaught-error-when-the-modifier-option-is-true-validation-object-must-have-at