MongoDB treats array fields specially during queries. A query on an array field will match documents where at least one element satisfies the condition — you don't need any special syntax to query arrays.
Implicit Array Matching
// Sample documents { _id: 1, tags: ["mongodb", "nosql", "database"] } { _id: 2, tags: ["mysql", "sql", "database"] } { _id: 3, tags: ["mongodb", "aggregation"] } // Find documents where tags contains "mongodb" db.articles.find({ tags: "mongodb" }) // Returns docs 1 and 3 — no $in or special syntax needed // MongoDB automatically checks if any element equals "mongodb" // Find by exact full array match (order matters!) db.articles.find({ tags: ["mongodb", "nosql", "database"] }) // Returns only doc 1 — exact array with that exact order
{ tags: "mongodb" } checks membership; querying { tags: ["mongodb"] } checks for exact array equality including order.Dot Notation on Array of Objects
// Documents with embedded arrays of objects { _id: 1, scores: [ { subject: "Math", val: 85 }, { subject: "Sci", val: 72 } ] } { _id: 2, scores: [ { subject: "Math", val: 40 }, { subject: "Sci", val: 90 } ] } // Find docs where ANY score object has subject "Math" db.students.find({ "scores.subject": "Math" }) // Returns both docs 1 and 2 // Find docs where ANY score has val > 80 db.students.find({ "scores.val": { $gt: 80 } }) // Returns doc 1 (85) and doc 2 (90) — checks across ALL elements
{ "scores.subject": "Math", "scores.val": { $gt: 80 } } matches ANY doc where some element has subject "Math" AND any element (possibly a different one) has val > 80. This is the classic gotcha — use $elemMatch to enforce same-element constraints.