Display all users of an app in a table

Hi there :slight_smile:

I’m actually working on an app on which i want to display all the users of this application (I’m working on an admin control panel).

Actually, i’m getting informations from mongo, perhaps it only show me the current user information … But i want all the users !

Here is my code :

userMain.js

Template.usersTreeView.helpers({
    usersTreeList: () => {
        return Meteor.users.find({});
    }
});

userHome.html

{{#each usersTreeList}}
                    <tr>
                        <td>{{_id}}</td>
                    </tr>
                {{/each}}

It works (i did the publish and subscribe part too of course :slight_smile: ). But it show me only one user ID when i presntly have 2 in mongoDB…

What do i missed ?

Moreover : I tried to display email info of this user by doing :

{{#each usersTreeList}}
                    <tr>
                        <td>{{emails[0].address}}</td>
                    </tr>
                {{/each}}

Nothing comes … What should i do here too ?

Thanks a lot :slight_smile:

Brawcks

By default, Meteor only publishes your own user to the client. If you want all users, you will need to write a publication on the server and subscribe to it on the client.

Be careful - you may be opening a security hole (e.g. exposing all user emails to anyone). Ensure you safeguard how you do this.

Hi @robfallows ,

Ok i see, i will of course take care of how informations are displayed on the app.

Could i ask you what you would write in the publication ? Actually, i have this :

Meteor.startup(() => {
    // code to run on server at startup
});

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

i don’t know what to do more to change the default way Meteor serves data :confused:

Have you subscribed to userList in the client?

Template.usersTreeView.onCreated(function() {
  this.subscribe('userList');
  //...
});

Hi there ! Sorry for the late answer :slight_smile:

Actually, i have this :


Template.usersTreeView.onCreated(function() {
    var self = this;
    self.autorun(function() {
        self.subscribe('userList');
    })
});

It seems to be okay for the subscribe part i think !