Answer the question
In order to leave comments, you need to log in
How to access collection elements in meteor.js?
I apologize for such a simple question, but the meteor.js documentation is very brief, many points are described rather vaguely. In general, how should the elements of collections be accessed in meteor ? Let's say we have a built-in User collection that stores user data. The user ID can be obtained using the following code on the client side: return Meteor.userId()
However, if you need to display other data (login, mail), then there is already a problem. After something like this code, the inscription [object Object] is displayed :
return Meteor.users.find({emails:"[email protected]"})
Answer the question
In order to leave comments, you need to log in
The problem is not in the meteor documentation, you need to know js before you start working on fancy meteors :)
Everything works correctly, you get back an object containing information about the user.
If in short:
Meteor.users.find({emails:"[email protected]"})._id // Если я не ошибаюсь хранится ID тут
Meteor.users.find({emails:"[email protected]"}).email
Meteor.users.find({emails:"[email protected]"}).login
Meteor.users.find({emails:"[email protected]"}).blah-blah
Not quite right
The find method returns the cursor, not the document itself from the database
To return the document itself - use .findOne or find(query,options).fetch() - which will return an array of documents
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question