Equality, range and array queries
corebeginnerA filter document is equality by default: { status: "shipped" } means exactly that value. Range queries add an operator like $gte. Querying a field that holds an array matches if any element matches.
Think of it as
Every filter key is a field name; every filter value is either a literal (equality) or an operator document like { $gte: 10 } (range). Nothing marks a field as "an array field" in the query — MongoDB just tries the match against the whole array first, then against each element, so the same { tags: "sale" } filter form works whether tags is a scalar or an array.
What we're doing: Show that a scalar filter against an array field matches on "any element," which surprises readers expecting exact-value semantics.
- 1
- tags is an array field with three string elements.
- 4
- A scalar equality filter on an array field matches if any element equals it — no $elemMatch or index needed for this simple case.
Why this works: This "any element" behavior is what makes tag-style array fields queryable without extra syntax — but it also means { tags: "sale" } and { tags: ["sale"] } mean different things: the first matches "sale" anywhere in the array, the second requires the array to be exactly that one-element array.
Expecting { field: [x] } to mean "the array contains x"
Wrong
Better
What you see: A query that should match several documents with varied tag arrays returns nothing, or only documents with that exact single-element array.
Why: A filter value that is itself an array is compared for exact array equality, not treated as "contains." Passing a bare scalar is what triggers the any-element match.
- equality — { status: "shipped" }
- range — { price: { $gte, $lt } }
- array — matches any element
The three basic query shapes
Together
Remember: Equality is a bare value, range is an operator document, and a scalar filter on an array field matches if any element matches.
See also: comparison operators · array operators

