Query on Embedded/Nested Documents
➤ Use the Select your language drop-down menu in the upper-right to set the language of the following examples.
Match an Embedded/Nested Document
For example, the following query selects all documents where the field size equals the document { h: 14, w: 21, uom: "cm" }:
Equality matches on the whole embedded document require an exact
match of the specified <value> document, including the field order. For example, the following query does not match any documents in the inventory collection:
Query on Nested Field
To specify a query condition on fields in an embedded/nested document, use dot notation ("field.nestedField").
Note
When querying using dot notation, the field and nested field must be inside quotation marks.
Specify Equality Match on a Nested Field
The following example selects all documents where the field uom nested in the size field equals "in":
Specify Match using Query Operator
The following query uses the less than operator ($lt) on the field h embedded in the size field:
Specify AND Condition
The following query selects all documents where the nested field h is less than 15, the nested field uom equals "in", and the status field equals "D":
Additional Query Tutorials
For additional query examples, see: