我的 Meteor.users 架构每次都无法通过验证

My schema for Meteor.users fails validation every time

我正在使用 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
  }
})

我是这样设置的:

Meteor.users.attachSchema(Schema.User)

为了检查它,我硬编码了一个值以添加一个具有完美电子邮件地址的用户:

Accounts.createUser({email: "fdfs@fdsfs.com"})

但是当我 运行 返回一个很大的异常时,除其他外,它说:

Exception while invoking method 'registerUser` Error: Email is required

at getErrorObject <packages/aldeed:collection2/collection2.js:369:1>

Sanitized and reported to the client as: Email is required [400]

我错过了什么?

如您在 the docs 中所见,user.emails 是一个对象数组,其属性为 verifiedaddress

所以尝试这样的事情:

emails: {
    type: [Object],
    optional: true
},

'emails.$.address': {
    type: String,
    regEx: SimpleSchema.RegEx.Email
},

'emails.$.verified': {
    type: Boolean
},