Search code examples
javascriptmongodbmeteorspacebars

Meteor display all users except currently logged in user


i'm currently doing a simple app with Meteor which requires displaying all users except for the current logged in user.

Here's my 'users' template which displays all the users:

<template name="friends">
    {{#each listUser}}
        <p id="userNameOnList">{{profile.firstname}} {{profile.lastname}} <a href="#" class="btn btn-primary btnAddFriend">Add Friend</a></p>
    {{/each}}
</template>

And here's my Template Helper:

Template.friends.helpers({
    listUser: function(){
        return Meteor.users.find({},{sort:{'profile.firstname': 1}});
    }
});

I'm a bit lost from here, can you give ideas on how I could handle the problem? Thank you!


Solution

  • Add your current userId in query. I didn't test the query but it will works

    Template.friends.helpers({
        listUser: function(){
            return Meteor.users.find({_id:{$ne:Meteor.userId()}},{sort:{'profile.firstname': 1}});
        }
    });