2

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

2 Answers 2

2

You can do it like this:

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

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

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.