【问题标题】:Accessing user info in server javascript在服务器 javascript 中访问用户信息
【发布时间】:2014-01-05 15:07:13
【问题描述】:

我正在制作一个用户使用 twitter 登录的两人游戏。如果我在控制台中搜索是否有用户登录(Meteor.users.find().count())它会返回曾经登录的用户数。在了解了这一点后,我安装了带有陨石的 userstatus 包。 db.users.find({'status.online' : true}).count() 使用终端在我的目录中启动 Meteor mongodb 显示当前连接的用户数。我制作了一个名为游戏的集合,为每两个唯一用户启动单独的游戏。我对下一步的猜测是搜索用户并将他们推送到一个数组中。我想搜索是否有超过 1 个用户登录并在满足正确条件时初始化游戏(2 个用户登录)。如何检查我的代码的if(Meteor.isServer){} 部分中是否有足够的用户登录而不是db.users.find().count()?

【问题讨论】:

    标签: javascript mongodb meteor meteorite


    【解决方案1】:

    github repo 给出了两个例子,都在coffeescript中,我使用http://js2coffee.org/#coffee2js将它们转换为Javascript

    https://github.com/mizzao/meteor-user-status

    “您可以在发布功能或模板助手中使用反应式光标来选择在线用户:”

    方案一:发布功能:

         Meteor.publish("userStatus", function() {
           return Meteor.users.find({
           "status.online": true
           }, {
           fields: {...}
        });
      });
    

    选项二:模板助手:

    Template.foo.usersOnline = function() {
       return Meteor.users.find({
         "status.online": true
      });
    };
    

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 2021-07-21
      • 2011-01-30
      • 2013-05-31
      • 2010-11-21
      • 2017-03-30
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      相关资源
      最近更新 更多