2016-02-29 50 views
0

我有一個顯示所有註冊用戶的頁面,但希望省略當前用戶。有沒有辦法讓當前用戶返回除了以外的所有流星用戶返回當前用戶以外的所有流星用戶?

這裏是我的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(); 
    }); 
} 

回答

1

你可以使用比較查詢操作$ne濾掉不等於指定值的文件,在你的情況Meteor.userId()

例如:

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

謝謝! @Matthias Eckhart –

+0

@LeonardParisi歡迎您!祝你今天愉快。 –

+0

我試圖做到這一點,但目前的用戶堅持和回來以及.. – webkit

0

如果您使用的是發佈,你可以簡單地使用$ne操作。作爲當前用戶在所有發佈功能上設置爲this.userId

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