MongoDB select where in array of _id?


is possible in mongo db to select collection’s documents like in SQL :

SELECT * FROM collection WHERE _id IN (1,2,3,4);

or if i have a _id array i must select one by one and then recompose the array/object of results?


Easy 🙂

db.collection.find( { _id : { $in : [1,2,3,4] } } );

taken from:

Answered By – programmersbook

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published