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

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

问题描述

我正在尝试使用以下命令通过电子邮件查询用户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({});
});

并在客户端订阅它们:

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.

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

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