Return 除当前用户外的所有 Meteor 用户?

Return All Meteor Users Except The Current User?

我有一个显示所有注册用户的页面,但想省略当前用户。有没有办法 return 所有 Meteor 的用户 除了 当前用户。

这是我的 html:

<template name="users">
    <div class="contentDiv">
        <div class="blueTop pageContent" id="profileName">Users</div>
            {{#each users}}
                <div class="pageContent text">
                    <a class="user link"  id="{{_id}}">{{profile.firstName}} {{profile.lastName}}</a>
                    <button class="addFriend">Add Friend</button>
                </div>
            {{/each}}
        </div>
    </div>    
</template>

还有我的javascript:

if (Meteor.isClient) {
    Meteor.subscribe("users");

    Template.users.helpers({
        users:function(){
            return Meteor.users.find({}, {sort: {firstName: -1}}).fetch();       
        }
    });
}


if (Meteor.isServer) {
    Meteor.publish("users",function(){
        return Meteor.users.find();
    });
}

您可以使用比较查询运算符 $ne 来过滤掉不等于指定值的文档,在您的例子中是 Meteor.userId()

例如:

Meteor.users.find({_id: {$ne: Meteor.userId()}});

如果您使用的是出版物,只需使用 $ne 运算符即可。 this.userId 以当前用户身份在所有发布功能上设置。

Meteor.publish('all_users', function () {
  return Meteor.users.find({
    _id: { $ne: this.userId }
  });
});