MongoDB select where in array of _id?

Easy :)

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

taken from: https://www.mongodb.com/docs/manual/reference/operator/query/in/#mongodb-query-op.-in


Because mongodb uses bson and for bson is important attribute types. and because _id is ObjectId you must use like this:

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

and in mongodb compass use like this:

{ "_id" : { $in : [ObjectId('1'),ObjectId('2')] } }

Note: objectId in string has 24 length.