stefankolb
stefankolb

Reputation: 328

How can I find entries that match a certain array of values with the mongo ruby driver

I know I can find entries in mongodb that match a certain array of values natively via this command:

db.vendors.find({"somearray.property": { $in: ["value1","value2"]}})

But how can I do this with the ruby driver 'mongo' gem?

col.find("somearray.property" => ["value1","value2"])

Regards

Upvotes: 2

Views: 1047

Answers (2)

toro2k
toro2k

Reputation: 19238

You can do it like this:

col.find("somearray.property" => { '$in' => ["value1","value2"] })

Upvotes: 2

Pierre-Louis Gottfrois
Pierre-Louis Gottfrois

Reputation: 17631

Not sure to understand what you mean by the "ruby driver" but if you are using mongoid (which I recommend when dealing with mongodb) you can do

col.where(:'somearray.property'.in => ["val1", "val2"])

More informations here

Upvotes: 1

Related Questions