Embedded Documents & Subdocuments
Embedding documents inside other documents is the most common way to model relationships in MongoDB, keeping connected data local and fast to query.
1 Querying Nested Fields
JavaScript — Nested Documents Query
# Query nested properties using dot notation (wrap in quotes)
db.users.find({ "address.city": "Hyderabad" });
# Query elements inside arrays
db.users.find({ hobbies: "coding" });
2 Code Challenge
Challenge: Write a query searching a product collection for products having a nested specification block containing weight properties greater than 10.