Learn › MongoDB fundamentals
Nested objects and arrays
Dot notation, matching array contents, and the trap everyone hits.
By the end: Query inside sub-documents and arrays of objects correctly.
Lessons
- Dot notation into nested objects
Query fields inside nested MongoDB objects with dot notation: { "address.city": "Bangalore" }, and why the path needs quotes.
- Querying arrays
How MongoDB matches arrays: a scalar match tests every element, and $all requires all of your values to be present.
- Arrays of objects
Querying arrays of sub-documents in MongoDB with dot notation, and what a match on "orders.status" actually tests.
- $elemMatch and the multi-condition trap
The classic MongoDB array trap: two conditions on an array of objects can match different elements. $elemMatch is the fix.