Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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 如何检查流星';s的用户帐户为空?_Meteor - Fatal编程技术网

Meteor 如何检查流星';s的用户帐户为空?

Meteor 如何检查流星';s的用户帐户为空?,meteor,Meteor,我试图在Meteor应用程序启动时创建一个默认用户,因此我检查users集合中是否有任何用户,但它不起作用 我试试这个: if (Meteor.users.find().count() === 0) { seedUserId = Accounts.createUser({ email: 'f@oo.com', password: '123456' }); } 此count()返回0,但在Mongo中我有用户: meteor:PRIMARY>db.users.find()

我试图在Meteor应用程序启动时创建一个默认用户,因此我检查users集合中是否有任何用户,但它不起作用

我试试这个:

if (Meteor.users.find().count() === 0) {
  seedUserId = Accounts.createUser({
    email: 'f@oo.com',
    password: '123456'
  });
}
此count()返回0,但在Mongo中我有用户:
meteor:PRIMARY>db.users.find().count()

>2

我也尝试过:
Meteor.users.findOne()
但是返回未定义的


我做错了什么???

您可能会看到一种竞争条件,即当您的代码执行时,服务器没有完全加载——尝试将代码包装在Meteor.startup中

if (Meteor.isServer) {
  Meteor.startup(function () {
    if (Meteor.users.find().count() === 0) {
       seedUserId = Accounts.createUser({
          email: 'f@oo.com',
          password: '123456'
       });
    }
  });
}

您是在服务器端还是客户端执行此操作?服务器端@Soren