user3070752 user3070752 - 1 year ago 79
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.

Answer Source

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) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download