Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform a "$in" query with Waterline and MongoDB

I am trying to do a "$in" query with waterline I have an Array and I want to get a list of document with ids that are in the array. I don't know how to do that.

I tried:

User.find()
.where({id : {in : array}})
done(...)

But it doesn't seem to work as expected.

Any way I can do that?

like image 826
adc06 Avatar asked Oct 03 '13 12:10

adc06


1 Answers

ParticleBanana answered me here: https://groups.google.com/forum/#!topic/sailsjs/dHxwsJvG5V8

I quote him here for convenience:

When an array is passed in the where criteria an IN query will automatically be run. So you can do the following:

User.find().where({ id: [1,2,3] }).exec(function(err, users) { ... })`

It worked perfectly.

like image 169
adc06 Avatar answered Nov 18 '22 21:11

adc06