Akil Demir
Akil Demir

Reputation: 160

how to query mongoDB to get the documents that have the _id value that matches one _id value in an array?

I have an array in Nodejs that contains document _id values of mongoDB documents that needs to be retrieved. So I need to query mongoDB such a way that it should return the documents that have the _id value that matches at least 1 _id value in the array that I want to pass in to query. The length of the array is unknown. I looked at the documentation but couldn't see something related.

Upvotes: 1

Views: 45

Answers (1)

mickl
mickl

Reputation: 49985

You can use $in operator:

db.col.find({ _id: { $in: [<value1>, <value2>, ... <valueN> ] } })

Upvotes: 4

Related Questions