Прикрепление схемы к Meteor.users

Я пытаюсь настроить свою схему 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]

Что мне здесь не хватает?


person L.Chen    schedule 06.02.2016    source источник


Ответы (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;
});

документы

person Michel Floyd    schedule 06.02.2016
comment
Спасибо за ответ! Я только что добавил функцию onCreateUser, настроил тест на профиль в моей схеме, и я уверен, что функция onCreateUser запущена. Но все же моя БД показывает пустое поле профиля. - person L.Chen; 06.02.2016
comment
Вот результат из базы данных {_id: ......, createdAt: ......., services: {пароль: {......}, резюме: {loginTokens: [{когда:... ..., hashedToken: ...... } ] } }, имя пользователя: ......, профиль: {} } - person L.Chen; 06.02.2016
comment
Извините, забыл options.profile.test, а не options.test - person Michel Floyd; 06.02.2016