【问题标题】:Attaching schema to Meteor.users将模式附加到 Meteor.users
【发布时间】:2016-02-06 06:26:33
【问题描述】:

我正在尝试自定义 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]

我在这里错过了什么?

【问题讨论】:

    标签: javascript meteor meteor-collection2


    【解决方案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

    【讨论】:

    • 感谢您的回复!我刚刚添加了 onCreateUser 函数,将“test”调整为我的架构中的配置文件,我确信 onCreateUser 函数被触发了。但我的数据库仍然显示空的个人资料字段。
    • 这是 db { "_id" : ......, "createdAt" : ......., "services" : { "password" : { .... .. }, "resume" : { "loginTokens" : [ { "when" : ......, "hashedToken" : ...... } ] } }, "username" : ..... ., "个人资料" : {} }
    • 抱歉,忘记了 options.profile.test 而不是 options.test
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-16
    • 2019-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-11
    • 1970-01-01
    相关资源
    最近更新 更多