Docs Home → Develop Applications → MongoDB Manual
Query on Embedded/Nested Documents
On this page
You can query embedded documents in MongoDB by using the following methods:
Your programming language's driver.
The MongoDB Atlas UI. To learn more, see Query Embedded Documents with MongoDB Atlas.
➤ Use the Select your language drop-down menu in the upper-right to set the language of the following examples or select MongoDB Compass.
Query on Nested Field with Dot Notation
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"
:
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" }
:
Warning
MongoDB does not recommend equality matches on embedded documents
because the operations 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:
The result of queries that use equality matches on embedded documents is undefined when used with a driver that does not use ordered data structures for expressing queries.
Query Embedded Documents with MongoDB Atlas
The example in this section uses the sample movies dataset. To learn how to load the sample dataset into your MongoDB Atlas deployment, see Load Sample Data.
To query an embedded document in MongoDB Atlas, follow these steps:
Specify the query filter document
Specify the query filter document in the Filter field. A query filter document uses query operators to specify search conditions.
Copy the following query filter document into the Filter search bar:
{ "awards.wins": 1 }
Additional Query Tutorials
For additional query examples, see: