How to select where in array of _id with Node.js MongoDB?

Sometimes, we want to select where in array of _id with Node.js MongoDB.

In this article, we’ll look at how to select where in array of _id with Node.js MongoDB.

How to select where in array of _id with Node.js MongoDB?

To select where in array of _id with Node.js MongoDB, we can use the collection find method with the $in operator.

For instance, we write

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

to call find with the _id property set to an object with $in set to [1, 2, 3, 4] to query for entries with _id 1, 2, 3, or 4.

Conclusion

To select where in array of _id with Node.js MongoDB, we can use the collection find method with the $in operator.