我正在尝试使用以下命令通过电子邮件查询用户
Meteor.users.findOne({'emails.address': 'me@example.com'});
它在mongo shell中工作,但它在Meteor中返回undefined.
有任何想法吗?
UPDATE
原来我无法查询其他用户.查询登录的用户电子邮件时,相同的查询有效.那么现在的问题是如何查询所有用户?
Ola*_*erg 12
默认情况下,Meteor仅发布登录用户,如您所述,您可以针对该用户运行查询.要访问其他用户,您必须在服务器上发布它们:
Meteor.publish("allUsers", function () {
return Meteor.users.find({});
});
Run Code Online (Sandbox Code Playgroud)
并在客户端订阅它们:
Meteor.subscribe('allUsers');
Run Code Online (Sandbox Code Playgroud)
另请注意,您可能不希望发布所有字段,以便指定要发布/不发布的字段:
return Meteor.users.find({},
{
// specific fields to return
'profile.email': 1,
'profile.name': 1,
'profile.createdAt': 1
});
Run Code Online (Sandbox Code Playgroud)
发布集合后,您可以为所有用户运行查询和访问信息.