将模式附加到Meteor.users

时间:2016-02-06 06:26:34

标签: javascript meteor meteor-collection2

我正在尝试自定义Meteor.users架构:

Schema.users = new SimpleSchema({
username: {
    type: String,
},
test:{
    type: String,
},
services: {
    type: Object,
    optional: true,
    blackbox: true
}
});

当我打电话时:

Accounts.createUser({username:"lionel",test:"123",password:"123"});

控制台返回:

Exception while invoking method 'createUser' Error: Test is required
......
Sanitized and reported to the client as: Test is required [400]

我在这里缺少什么?

1 个答案:

答案 0 :(得分:1)

Accounts.createUser()期望在profile密钥中出现额外信息。

使用:

Accounts.createUser({username:"lionel",password:"123",profile: {test:"123"}});

并在服务器上设置Accounts.onCreateUser()功能:

Accounts.onCreateUser(function(options, user) {
  if (options.profile) user.test = options.profile.test;
  return user;
});

docs