1

I have this collection:

{"_id"=>BSON::ObjectId('5728cd81c08460ead'), "age"=>4, "name"=>"Diogo"}
{"_id"=>BSON::ObjectId('5728cd81c08460ead'), "age"=>22, "name"=>"Tiago"}
{"_id"=>BSON::ObjectId('5728cd81c08460ead'), "age"=>15, "name"=>"Marie"}
{"_id"=>BSON::ObjectId('5728cd81c08460ead'), "age"=>2, "name"=>"JJ"}
{"_id"=>BSON::ObjectId('5728cd81c08460ead'), "age"=>44, "name"=>"John"}

and this array of names:

names_array = ["John", "Marie", "Tiago"]

How can I use names_array to search for names in mongodb collection?

I want this output:

{"_id"=>BSON::ObjectId('5728cd81c08460ead'), "age"=>4, "name"=>"Diogo"}
{"_id"=>BSON::ObjectId('5728cd81c08460ead'), "age"=>22, "name"=>"Tiago"}
{"_id"=>BSON::ObjectId('5728cd81c08460ead'), "age"=>15, "name"=>"Marie"}

this query not work :

coll.find( { name: names_array } )

1 Answer 1

2
coll.find('name' => { '$in' => names_array } } )
Sign up to request clarification or add additional context in comments.

2 Comments

I can't. undefined method `where' for #<Mongo::Collection:0x007fb2f912a738>
where method available in the mongo ORM.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.