流星通过电子邮件查询其他用户 [英] Meteor Querying other users by email

查看:78
本文介绍了流星通过电子邮件查询其他用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下命令通过电子邮件查询用户 Meteor.users.findOne({'emails.address': 'me@example.com'});

I'm trying to query users by emails with the following command Meteor.users.findOne({'emails.address': 'me@example.com'});

它在mongo shell中有效,但在Meteor中返回undefined.

It works in the mongo shell but it returns undefined in Meteor.

有什么想法吗?

更新

原来,我无法查询其他用户.当我查询登录的用户电子邮件时,相同的查询有效. 那么现在的问题是如何查询所有用户?

Turned out that I'm not able to query other users. The same query works when I query the logged in user email. So the question now how can I query on all the users?

推荐答案

默认情况下,Meteor仅发布已登录的用户,并且您可以如上所述针对该用户运行查询.为了访问其他用户,您必须将他们发布在服务器上:

By default, Meteor only publishes the logged in user and you can, as you mention, run queries against that user. In order to access the other users you have to publish them on the server:

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

并在客户端上订阅它们:

And subscribe to them on the client:

Meteor.subscribe('allUsers');

还请记住,您可能不想发布所有字段,因此可以指定要发布/不发布的字段:

Also keep in mind that you might not want to publish all the fields so you can specify what fields you like to publish/not publish:

return Meteor.users.find({}, 
{
     // specific fields to return
     'profile.email': 1,
     'profile.name': 1,
     'profile.createdAt': 1
});

发布收藏集后,您可以为所有用户运行查询和访问信息.

Once you have published the collection, you can run queries and access information for all the users.

这篇关于流星通过电子邮件查询其他用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆