Categories
JavaScript Answers

How to select where in array of _id with MongoDB and JavaScript?

Spread the love

To select where in array of _id with MongoDB and JavaScript, we call the find method.

For instance, we write

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

to call find with an object with the _id property set to an array with the object IDs to look for in the collection.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *