简体   繁体   English

流星如何获得所有用户

[英]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 https://docs.meteor.com/api/collections.html#fieldspecifiers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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