Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

Query on Embedded/Nested Documents

On this page

  • Match an Embedded/Nested Document
  • Query on Nested Field
  • Additional Query Tutorials

Use the Select your language drop-down menu in the upper-right to set the language of the following examples.


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:

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.

The following example selects all documents where the field uom nested in the size field equals "in":

The following query uses the less than operator ($lt) on the field h embedded in the size field:

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":

For additional query examples, see:

←  Query DocumentsQuery an Array →