Displaying all users in Meteor

12,229

Solution 1

if you want show all the user you can try in your publish.js file:

Meteor.publish('userList', function (){ 
  return Meteor.users.find({});
});

in your router you susbcribe to this

Router.route('/users', {
    name: 'usersTemplate',
    waitOn: function() {
        return Meteor.subscribe('userList');
    },
    data: function() {
        return Meteor.users.find({});       
    }
 });

The next step is iterate your data in the template.

if you don't want subscribe in the router, you can subscribe in template level, please read this article for more details.

https://www.discovermeteor.com/blog/template-level-subscriptions/

Regards.

Solution 2

This should work!

// in server

    Meteor.publish("userList", function () {
           return Meteor.users.find({}, {fields: {emails: 1, profile: 1}});
    });

// in client

    Meteor.subscribe("userList");
Share:
12,229
Admin
Author by

Admin

Updated on July 08, 2022

Comments

  • Admin
    Admin almost 2 years

    I have a template that I am trying to display all users in called userList.

    //server

    Meteor.publish("userList", function() {
    
    var user = Meteor.users.findOne({
        _id: this.userId
    });
    
    
    if (Roles.userIsInRole(user, ["admin"])) {
        return Meteor.users.find({}, {
            fields: {
                profile_name: 1,
                emails: 1,
                roles: 1
            }
        });
    }
    
    this.stop();
    return;
    });
    

    Thanks in advance for the help!

  • Admin
    Admin almost 9 years
    Thanks for the input, but I'm not able to iterate through these in my template. Do you know how that would look?
  • Barry Michael Doyle
    Barry Michael Doyle over 8 years
    How do you iterate the data in the template?