Search code examples
meteormeteor-accounts

How to return all the users inside Meteor.users except for the current logged in user?


I have a master user in my database that should be able to view all the users in the system.

Here is my code that return all the users in the collection.

Template.listEmployees.helpers({
    employees: function () {
            return Meteor.users.find({}, { sort: {createdAt: -1}});
        }
    });

Is it possible to return all the users except for the current logged in user?


Solution

  • Just exclude their _id:

    Template.listEmployees.helpers({
      employees() {
        return Meteor.users.find({ _id: { $ne: Meteor.userId() }}, { sort: { createdAt: -1 }});
      }
    });