I’m trying to query users by emails with the following command
Meteor.users.findOne({'emails.address': 'me@example.com'});
It works in the mongo shell but it returns undefined in Meteor.
Any ideas?
UPDATE
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?
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:
And subscribe to them on the client:
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:
Once you have published the collection, you can run queries and access information for all the users.