mongodb/mongoose findMany – find all documents with IDs listed in array

I have an array of _ids and I want to get all docs accordingly, what’s the best way to do it ?

Something like …

// doesn't work ... of course ...

model.find({
    '_id' : [
        '4ed3ede8844f0f351100000c',
        '4ed3f117a844e0471100000d', 
        '4ed3f18132f50c491100000e'
    ]
}, function(err, docs){
    console.log(docs);
});

The array might contain hundreds of _ids.

9 Answers
9

Leave a Comment