user3070752 user3070752 - 2 months ago 17
Node.js Question

How to find items in a collection whose IDs are in an array?

I have a collection named

and I want to find all vendors whose IDs are in a list of IDs. Is there any way to do it in Sails.js or I must iterate over the list to find those whose IDs match with one item in the list.

I'm using MongoDB in Sails.


You can use the $in operator within the .native() method as follows

Vendor.native(function(err, collection) {
    if (err) return console.log(err);
    collection.find({ "_id": { "$in": ids } }).toArray(function(err, results) {