Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 如何向用户集合添加额外属性?_Meteor_Meteor Accounts - Fatal编程技术网

Meteor 如何向用户集合添加额外属性?

Meteor 如何向用户集合添加额外属性?,meteor,meteor-accounts,Meteor,Meteor Accounts,我正在使用Accounts.createUser向数据库添加新用户,但问题是,并不是所有属性都被添加 以下是我添加新用户的代码: import {Accounts} from 'meteor/accounts-base'; Template.addingUser.events({ 'submit #addUser': function (e, t) { e.preventDefault(); Session.set('name', t.find('#

我正在使用
Accounts.createUser
向数据库添加新用户,但问题是,并不是所有属性都被添加

以下是我添加新用户的代码:

import {Accounts} from 'meteor/accounts-base';

Template.addingUser.events({
    'submit #addUser': function (e, t) {

        e.preventDefault();

        Session.set('name', t.find('#name').value);
        Session.set('email', t.find('#email').value);
        Session.set('telephoneOffice', t.find('#telephoneOffice').value);
        Session.set('telephoneHouse', t.find('#telephoneHouse').value);
        Session.set('salary', t.find('#salary').value);

        let userId = Accounts.createUser({
            username: Session.get('name'),
            password: "123456",
            email: Session.get('email'),
            telephoneOffice: Session.get('telephoneOffice'),
            telephoneHouse: Session.get('telephoneHouse'),
            employeeSalary: Session.get('salary'),
            annualLeave: 14

        }, function (err) {
            if (err)
                console.log(err);
            else
                console.log('It worked...');
        });

        Accounts.sendEnrollmentEmail(userId);


    }
});
只添加名称、电子邮件和密码


如何包括其他信息,如
telephoneOffice

帐户。createUser
不接受用户名、电子邮件、密码和配置文件以外的自定义参数。传递自定义用户信息的默认功能是传递那些字段,例如
telephoneOffice
,作为
profile
对象的一部分,该对象复制到插入到用户集合的文档中的
user.profile

例如:

let userId = Accounts.createUser({
        username: Session.get('name'),
        password: "123456",
        email: Session.get('email'),
        profile: {
          telephoneOffice: Session.get('telephoneOffice'),
          telephoneHouse: Session.get('telephoneHouse'),
          employeeSalary: Session.get('salary'),
          annualLeave: 14
        }
    });
请注意,
user.profile
字段为。所以它是遗留下来的,但Meteor实际上建议避免将其用于存储

如果希望这些字段位于
user
而不是
user.profile
上,可以做的是如上所述在
profile
对象上传递自定义参数,然后使用重写默认行为。大概是这样的:

Accounts.onCreateUser(function(options, user) {
  if (options.profile)
    _.extend(user, options.profile);
  return user;
});

请参阅此处的更多信息:

帐户。createUser
不接受用户名、电子邮件、密码和配置文件以外的自定义参数。传递自定义用户信息的默认功能是传递那些字段,例如
telephoneOffice
,作为
profile
对象的一部分,该对象复制到插入到用户集合的文档中的
user.profile

例如:

let userId = Accounts.createUser({
        username: Session.get('name'),
        password: "123456",
        email: Session.get('email'),
        profile: {
          telephoneOffice: Session.get('telephoneOffice'),
          telephoneHouse: Session.get('telephoneHouse'),
          employeeSalary: Session.get('salary'),
          annualLeave: 14
        }
    });
请注意,
user.profile
字段为。所以它是遗留下来的,但Meteor实际上建议避免将其用于存储

如果希望这些字段位于
user
而不是
user.profile
上,可以做的是如上所述在
profile
对象上传递自定义参数,然后使用重写默认行为。大概是这样的:

Accounts.onCreateUser(function(options, user) {
  if (options.profile)
    _.extend(user, options.profile);
  return user;
});

请参阅此处的更多信息:

您需要在
配置文件
对象中传递额外的数据

Accounts.createUser({
  username: Session.get('name'),
  password: "123456",
  email: Session.get('email'),
  profile: {
    telephoneOffice: Session.get('telephoneOffice'),
    telephoneHouse: Session.get('telephoneHouse'),
    employeeSalary: Session.get('salary'),
    annualLeave: 14
  }
  ...

您需要在
profile
对象中传递额外的数据

Accounts.createUser({
  username: Session.get('name'),
  password: "123456",
  email: Session.get('email'),
  profile: {
    telephoneOffice: Session.get('telephoneOffice'),
    telephoneHouse: Session.get('telephoneHouse'),
    employeeSalary: Session.get('salary'),
    annualLeave: 14
  }
  ...