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.
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"]}})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With