Query an Array¶
➤ Use the Select your language drop-down menu in the upper-right to set the language of the following examples.
Match an Array¶
The following example queries for all documents where the field
value is an array with exactly two elements,
in the specified order:
If, instead, you wish to find an array that contains both the elements
"blank", without regard to order or other elements in
the array, use the
Query an Array for an Element¶
The following example queries for all documents where
tags is an
array that contains the string
"red" as one of its elements:
For example, the following operation queries for all documents where the array
dim_cm contains at least one element whose value is greater than
Specify Multiple Conditions for Array Elements¶
When specifying compound conditions on array elements, you can specify the query such that either a single array element meets these condition or any combination of array elements meets the conditions.
Query an Array with Compound Filter Conditions on the Array Elements¶
The following example queries for documents where the
contains elements that in some combination satisfy the query
conditions; e.g., one element can satisfy the greater than
condition and another element can satisfy the less than
condition, or a single element can satisfy both:
Query for an Array Element that Meets Multiple Criteria¶
$elemMatch operator to specify multiple criteria on the
elements of an array such that at least one array element satisfies all
the specified criteria.
Query for an Element by the Array Index Position¶
Using dot notation, you can specify query conditions for an element at a particular index or position of the array. The array uses zero-based indexing.
When querying using dot notation, the field and nested field must be inside quotation marks.
The following example queries for all documents where the second
element in the array
dim_cm is greater than
Query an Array by Array Length¶
$size operator to query for arrays by number of
elements. For example, the following selects documents where the array
tags has 3 elements.
Additional Query Tutorials¶
For additional query examples, see: