Yea*_*ats 2 javascript schema meteor meteor-collection2
我正在使用如下所示的collection2包:https://github.com/aldeed/meteor-collection2
我已经设置了一个简单的模式,其中只有email一个非可选值,但尽管这样简单,每次声称"需要电子邮件"时验证都会失败.
我的架构:
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
},
likes: {
type: [String],
optional: true
}
})
Schema.User = new SimpleSchema({
username: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,15}$/,
optional: true
},
email: {
type: String,
regEx: SimpleSchema.RegEx.Email
},
verified: {
type: Boolean,
optional: true
},
createdAt: {
type: Date,
optional: true
},
profile: {
type: Schema.UserProfile,
optional: true
},
services: {
type: Object,
optional: true,
blackbox: true
}
})
Run Code Online (Sandbox Code Playgroud)
我这样设置:
Meteor.users.attachSchema(Schema.User)
Run Code Online (Sandbox Code Playgroud)
只是为了检查它我硬编码一个值来添加一个完美的电子邮件地址的用户:
Accounts.createUser({email: "fdfs@fdsfs.com"})
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,会返回一个很大的异常,除其他外:
调用方法'registerUser`时出现异常错误:需要电子邮件
在getErrorObject
<packages/aldeed:collection2/collection2.js:369:1>消毒并向客户报告:需要电子邮件[400]
我错过了什么?
正如您在文档中看到的那样,user.emails是一个具有属性verified和对象的对象数组address.
所以尝试这样的事情:
emails: {
type: [Object],
optional: true
},
'emails.$.address': {
type: String,
regEx: SimpleSchema.RegEx.Email
},
'emails.$.verified': {
type: Boolean
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
897 次 |
| 最近记录: |