W
W
Wasya UK2017-05-02 20:18:27
MongoDB
Wasya UK, 2017-05-02 20:18:27

What is the best way to search to create conversations in MongoDb?

I have an array of messages. From it, an array of id of those people with whom the user is corresponding is formed. In order to form a page of correspondence, I need to select people from the database and take some data I need about each of them. ( avatar, name, status: online, online, ...... )
What is the best way to search?
in one gulp

User.find({_id: {$in: dialogPersons}}, function(err, persons)

Or choose each one individually, and then give the result?
Thanks in advance)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lega, 2017-05-02
@dmc1989

Gulp faster.

P
Philipp, 2017-05-02
@zoonman

You can use populate() , it will effectively do this for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question