N
N
Nikita Pospelov2015-01-02 19:17:15
JavaScript
Nikita Pospelov, 2015-01-02 19:17:15

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]"})

What is the correct syntax for displaying collection items and what am I missing?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2015-01-03
@Sanasol

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

Y
Yura Zubarev, 2018-08-16
@zentelechia

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 question

Ask a Question

731 491 924 answers to any question