mongoose model find all documents with ids in array

Solutions on MaxInterview for mongoose model find all documents with ids in array by the best coders in the world

showing results for - "mongoose model find all documents with ids in array"
Ibtissem
26 Apr 2019
1const ids =  [
2    '4ed3ede8844f0f351100000c',
3    '4ed3f117a844e0471100000d', 
4    '4ed3f18132f50c491100000e',
5];
6
7// 3 Methods below:
8// Using Mongoose with async function:
9const records = await Model.find().where('_id').in(ids).exec();
10
11// Or more concise:
12const records = await Model.find({ '_id': { $in: ids } });
13
14// Using Mongoose with callback:
15Model.find().where('_id').in(ids).exec((err, records) => {});