Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 955
prototype Avatar asked Jan 09 '14 20:01

prototype


1 Answers

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
    });
like image 52
prototype Avatar answered Nov 14 '22 13:11

prototype