How do you do an AND query on an array in mongodb?
问题 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. 回答1: 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"]}}) 回答2: Also in case someone is wondering how to