繁体   English   中英

如何更改 Meteor.users _id?

[英]How can I change a Meteor.users _id?

我有一些来自非 Meteor 应用程序的现有用户。 我想导入它们并保留它们的 _id,因为我在其他文档中引用了它。

我能够创建这样的用户:

if (Meteor.users.find().count() === 0) {
    Accounts.createUser({
      username: 'test',
      email: 'test@example.com',
      password: 'password'
    });
  }

但是,在该代码块中设置 _id 字段似乎不起作用。

有没有办法改变用户的_id?

尝试使用Meteor.users.insert而不是Accounts.createUser 它稍微复杂一些,需要额外的步骤来设置密码:

var newUserId = Meteor.users.insert({
      _id: 'whatever',
      profile  : { fullname : 'test' },
      email: ['test@example.com']
    })
Accounts.setPassword(newUserId, 'password');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM