尝试在StackOverflow和meteor-simple-schema的文档之间进行读取但无法找到解决方案。我想通过表单在Meteor.users集合中插入数据。但不断收到错误:
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。(匿名函数)@ collection2.js:154(匿名函数)@ VM47084:2InjectedScript._evaluateOn @ VM47083:883InjectedScript._evaluateAndWrap @ VM47083:816InjectedScript.evaluate @ VM47083:682
有任何线索吗?
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});
}
});
}
和架构
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);
非常感谢。
答案 0 :(得分:2)
尝试此架构
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();
}
}
}
});
顺便说一下,如果您使用的是帐户密码,那么此架构将无法正常工作,因为该程序包希望以某种方式存储电子邮件。