简体   繁体   中英

Meteor how to get all users

How can I get all the users on the system, but for security reasons only get certain fields from it. I do not want to return the entire objects as it would have fields in there that are private.

I have a publish method: I am unsure if I need an import? The fields I need are: - username - age - level

Meteor.publish("allUsers", function(){
return Meteor.users.find({});
});

on the client side I have:

    allUsers(){
        Meteor.call('allUsers', function(error, result) {
            return result;
        });
    }

and in the render I have:

        {this.allUsers().map((user) => {
            return <UserSearchRow
            key={user._id} 
            user={user} />
        })}
Meteor.publish("allUsers", function() {
  return Meteor.users.find({}, {fields: {username: 1, age: 1, level: 1}});
});

https://docs.meteor.com/api/collections.html#fieldspecifiers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM