Search code examples
javascriptnode.jsmongodbsails.jswaterline

Sails.js find multiple database entries by id


I'm bit new at node.js/sails.js and was wondering (if possible) how to retrieve multiple database entries by searching for their ids - there is something like this mentioned in the MongoDB documentation:

db.inventory.find( { qty: { $in: [ 5, 15 ] } } )

And here is what i've tried:

// users param example: 12341243124, 1231231231, 21312313212
var users = req.param('users').split(',');

User.find({id: { $in: users }}, function (err, response) {
  // do something here
});

Any help would be appreciated! Thanks!


Solution

  • Sorry for bothering - as it turns out Waterline supports array parameters - so by changing the code above a bit i got this to work:

    User.find()
        .where({id: users})
        .exec(function (err, response) {
            // do stuff
        });