Javascript 未捕获错误:当修饰符选项为true时,验证对象必须至少有一个运算符
试图阅读StackOverflow和meteor simple schema的文档,但找不到解决方案。我正试图通过表单在Meteor.users集合中插入数据。但不断出现错误:Javascript 未捕获错误:当修饰符选项为true时,验证对象必须至少有一个运算符,javascript,mongodb,meteor,Javascript,Mongodb,Meteor,试图阅读StackOverflow和meteor simple schema的文档,但找不到解决方案。我正试图通过表单在Meteor.users集合中插入数据。但不断出现错误: Uncaught Error: When the modifier option is true, validation object must have at least one operator 检查修改器 @simple schema validation.js:271doValidation1@simple s
Uncaught Error: When the modifier option is true, validation object must have at least one operator
检查修改器
@simple schema validation.js:271doValidation1@simple schema validation.js:321doValidation@simple schema context.js:9SimpleSchema ValidationContextValidate@simple schema context.js:44doValidate@collection2.js:317\ each.Mongo.Collection.(匿名函数)@collection2.js:154(匿名函数)@VM47084:2 InjectedScript.\u evaluateOn@VM47083:883InjectedScript.\u 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: 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();
}
}
}
});
顺便说一句,如果您使用的是帐户密码,那么此模式将无法工作,因为该软件包希望电子邮件以某种方式存储 你什么时候得到那个错误的?到目前为止,你尝试了什么?@ChristianFritz我认为与简单模式有关,我在配置中遗漏了一些东西。当我在没有Schema部分的情况下运行表单时,效果很好。@eliosolutions,请参阅。尝试将“服务:{type:Object,blackbox:true}”添加到您的模式中。用户定义。谢谢@MarkLeiber它成功了!救了我一天。
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();
}
}
}
});