Complete the code to find documents where the 'tags' array contains the value 'mongodb'.
db.collection.find({ tags: [1] })To find documents where the array contains a specific value, you can directly query with that value. Here, 'tags: "mongodb"' matches documents where 'tags' array includes 'mongodb'.
Complete the code to find documents where the 'scores' array contains at least one value greater than 80.
db.collection.find({ scores: { [1]: 80 } })The operator $gt means 'greater than'. So, this query finds documents where the 'scores' array has at least one element greater than 80.
Fix the error in the query to find documents where the 'comments' array contains an object with 'author' equal to 'Alice'.
db.collection.find({ comments: { [1]: { author: "Alice" } } })The $elemMatch operator matches documents where at least one element in the array matches the specified query. Here, it finds documents with a 'comments' array containing an object with 'author' equal to 'Alice'.
Fill both blanks to find documents where the 'ratings' array has exactly 3 elements and contains the value 5.
db.collection.find({ ratings: { [1]: 3, [2]: [5] } })$size checks the array length, so $size: 3 means the array has exactly 3 elements. $in checks if the array contains the value 5.
Fill all three blanks to create a query that finds documents where the 'reviews' array contains an object with 'score' greater than 7 and 'verified' equal to true.
db.collection.find({ reviews: { [1]: { score: { [2]: 7 }, verified: { [3]: true } } } })$elemMatch matches array elements by multiple conditions. Inside it, $gt checks if 'score' is greater than 7, and $eq checks if 'verified' is true.