Meteor简单模式-当修饰符选项为true时,验证对象必须至少有一个运算符
Meteor Simple Schema - When the modifier option is true, validation object must have at least one operator
当我尝试创建用户时,我一直得到错误:Exception while invoking method 'createUser' Error: When the modifier option is true, validation object must have at least one operator
。我使用的是流星简单模式,但没有一个修复这个错误的方法对我有效。我尝试过使用blackbox和optional来查看问题所在,但我一直收到同样的错误。
var Schemas = {};
Schemas.UserGamesPart = {
public: {
type: [String],
defaultValue: []
},
private: {
type: [String],
defaultValue: []
}
};
Schemas.UserGames = {
game1: {
type: Schemas.UserGamesPart
}
};
Schemas.UserProfile = new SimpleSchema({
games: {
type: Schemas.UserGames
}
});
Schemas.UpgradeDetails = new SimpleSchema({
subscribed_on: {
type: Date,
optional: true
},
stripe_charge_id: {
type: String,
optional: true
},
school_license: {
type: Boolean,
defaultValue: false,
optional: true
}
});
Schemas.UserProperties = new SimpleSchema({
paid: {
type: Boolean,
defaultValue: false
},
upgrade_details: {
type: Schemas.UpgradeDetails,
optional: true
}
});
Schemas.User = new SimpleSchema({
_id: {
type: String
},
username: {
type: String,
optional: true
},
emails: {
type: [Object]
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email,
optional: true
},
"emails.$.verified": {
type: Boolean,
optional: true
},
createdAt: {
type: Date
},
profile: {
type: Schemas.UserProfile,
blackbox: true,
optional: true
},
properties: {
type: Schemas.UserProperties,
blackbox: true,
optional: true
}
});
Meteor.users.attachSchema(Schemas.User);
我的accounts.creaate用户如下:
Accounts.createUser({
email: $('#email').val(),
password: $('#password').val(),
profile: {
games: {
game1: {
public: [],
private: []
}
}
}
});
有什么想法可以让它发挥作用吗?
您忘记在开头添加new SimpleSchema
:
Schemas.UserGamesPart = new SimpleSchema({
public: {
type: [String],
defaultValue: []
},
private: {
type: [String],
defaultValue: []
}
});
Schemas.UserGames = new SimpleSchema({
game1: {
type: Schemas.UserGamesPart
}
});
此外,我认为您对嵌套模式的使用有点偏离。当您需要重用嵌套模式时,仅嵌套模式。为UserGamesPart
创建一个单独的模式看起来很可怕。试试这个:
Schemas.UserGames = new SimpleSchema({
game1: {
type: Object
}
'game1.public': {
type: [String],
defaultValue: []
},
'game1.private': {
type: [String],
defaultValue: []
}
});
这本书更短,更容易阅读。
相关文章:
- 验证会话中是否存在对象's数组
- 验证对象是否为null Javascript/Angularjs
- 在页面对象文件中验证sendKeys结果会导致未定义的错误(Protractor)
- 在对象上迭代以验证它是否's键存在于数组中
- 类型错误:对象 #<对象> 没有方法“身份验证”
- 如何使用对象初始值设定项验证窗体
- Join验证对象数组,这样只有一个对象具有特定属性
- 使用正则表达式对象进行Javascript字符串验证
- 我可以使用一个函数来帮助分配和验证作为对象传递的属性吗
- JS 字段验证 - 循环遍历对象,每个字段有三个数据注意事项
- 如何验证是否使用 Selenium 在 javascript 对象上调用了某些方法
- Angular Js:验证表中的重复对象键
- 未捕获的类型错误:对象 [对象对象] 没有方法“验证引擎”
- 使用 Jquery 验证 JavaScript 对象是否为空
- 如何从 Passport.js 更改本地策略身份验证的用户对象
- 身份验证后将用户对象返回到父页面,无需刷新页面
- 如何使用 javascript 对象验证表单字段
- AngularJS验证引用具有变量名称的表单对象
- 验证输入字符串并将其转换为新的 Date 对象
- 获取“null”或“不是对象”;验证表单时出错