Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.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分配\u id_Meteor - Fatal编程技术网

创建用户时Meteor分配\u id

创建用户时Meteor分配\u id,meteor,Meteor,我想在创建meteor用户时分配他们的_idMeteor.createUser()似乎不允许这样做 还有其他方法吗?Accounts.onCreateUser存在于服务器上,允许在插入用户文档之前对其进行自定义。下面的代码修改文档,新用户出现在数据库中,客户端上的用户使用定制的_id登录 //in server js code Accounts.onCreateUser( function( options, user){ user._id = 'myId' + Math.floor( Ma

我想在创建meteor用户时分配他们的_id<代码>Meteor.createUser()似乎不允许这样做


还有其他方法吗?

Accounts.onCreateUser存在于服务器上,允许在插入用户文档之前对其进行自定义。下面的代码修改文档,新用户出现在数据库中,客户端上的用户使用定制的_id登录

//in server js code
Accounts.onCreateUser( function( options, user){
  user._id = 'myId' + Math.floor( Math.random() * 1000 ) + 1;
  if (options.profile)
    user.profile = options.profile; //careful not to drop the profile if it exists
  return user;
});
函数文档和一个非常类似的示例如下-