使用meteor列出客户端上的所有用户

使用meteor列出客户端上的所有用户,meteor,coffeescript,Meteor,Coffeescript,根据meteor文档,如果安装了autopublish软件包,则应将所有用户发布到所有客户端 我安装了autopublish软件包,但在Meteor上使用了forEach。users仅列出当前登录的用户 是否有更正确的方法使用coffeescript列出客户端上的所有用户?如果您在不使用subscribe的情况下自动发布用户集合 if Meteor.isServer Meteor.publish null, -> Meteor.users.find {},

根据meteor文档,如果安装了autopublish软件包,则应将所有用户发布到所有客户端

我安装了autopublish软件包,但在Meteor上使用了
forEach
。users仅列出当前登录的用户


是否有更正确的方法使用coffeescript列出客户端上的所有用户?

如果您在不使用subscribe的情况下自动发布用户集合

if Meteor.isServer

    Meteor.publish null, ->
        Meteor.users.find {},
            fields:
                username: 1
                profile: 1
如果要订阅,请指定用户,您可以

if Meteor.isServer

    Meteor.publish 'users-by-selector', (options) ->
        Meteor.users.find options, # options as selector like $in: name: 'john'
            fields: # use fields to only publish specify fields you want to send. 
                username: 1
                profile: 1

if Meteor.isClient

    Meteor.autosubscribe ->
        options = Session.get 'your mongodb selector'
        Meteor.subscribe 'users-by-selector', options, ->
            console.log 'on Subscribe Complete Callback.'
            if Meteor.users.find().count()
                Session.set 'specifyUsersLoaded', true

以下是《流星》的节选:


您的第一个代码片段很有效,但我必须在
字段下添加
电子邮件:1
,因为
用户名和
个人资料对于所有用户都是空的。显然,除非用户的自动发布字段中有值,否则用户不会自动发布。我没有发现@danielsvane提到的限制。不过,需要注意的一点是,不同的提供者包提供不同的数据结构。当你考虑它时,这是有道理的,但如果你还没有准备好,它可能会让人困惑@上面的crapthings代码(包括
profile
username
)可以很好地获取Facebook和
帐户密码
包的用户名。要从
用户
记录中获取用户名,您需要
user.username | | user.profile.name
。非常有用的答案+1,但假设使用CoffeeScript则需要-1。问题未标记为CoffeeScript。它不叫流星。coffee@BjornTipling我用的是咖啡脚本,所以他的回答很准确。@Danielsvine你在问题中到底在哪里用的咖啡脚本?这是文档中的一个bug吗?有一个相关的已解决问题示例已不存在,我如何在模板中迭代每个用户?这里是:(代码相同,更新链接)
// in server.js
Meteor.publish("directory", function () {
  return Meteor.users.find({}, {fields: {emails: 1, profile: 1}});
});

// in client.js
Meteor.subscribe("directory");