tags:

views:

205

answers:

1

I have an array with tags which is part of a document, eg ["red", "green", "blue", "white", "black"]

Now I want to find all documents, which have red AND blue.

+4  A: 

Use the $all condition to find records that match both "red" and "blue" conditions.

db.my_collection.find({tags: { $all : ["red","blue"]}})

If you want records that match either "red" or "blue" then you can use the $in condition.

db.my_collection.find({tags: { $in : ["red","blue"]}})
Hates_
Thanks, works fine ;)
Piotr Zolnierek