0
0
MongoDBquery~10 mins

Dot notation for embedded documents in MongoDB - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Dot notation for embedded documents
Start with collection
Identify embedded document
Use dot notation: 'parent.child'
Query or update using dot notation
Return or modify embedded field value
Dot notation lets you access or change fields inside embedded documents by writing 'parent.child'.
Execution Sample
MongoDB
db.users.find({"address.city": "Boston"})
Finds users whose embedded address document has city equal to Boston.
Execution Table
StepActionQuery PartEvaluationResult
1Start query on 'users' collectionAll user documents available
2Look inside each document's 'address' fieldaddressCheck if 'address' exists and is a documentAccess embedded document
3Access 'city' inside 'address' using dot notationaddress.cityCompare city value to 'Boston'True or False per document
4Return documents where city is 'Boston'address.city = 'Boston'Filter appliedDocuments matching condition
5End queryResult set returned
💡 Query ends after filtering all documents by embedded field 'address.city' equals 'Boston'
Variable Tracker
VariableStartAfter Step 2After Step 3Final
current_documentFull user docEmbedded 'address' doc extracted'city' field value extractedDocument included or excluded based on city
Key Moments - 2 Insights
Why do we write 'address.city' instead of just 'city'?
Because 'city' is inside the embedded 'address' document, so dot notation 'address.city' tells MongoDB to look inside 'address' for 'city' (see execution_table step 3).
What happens if a document has no 'address' field?
The query skips that document because 'address.city' cannot be found, so the condition is false (see execution_table step 2 and 3).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step do we check the 'city' value inside 'address'?
AStep 2
BStep 4
CStep 3
DStep 1
💡 Hint
Check the 'Query Part' column for 'address.city' in execution_table rows.
According to variable_tracker, what is the value of 'current_document' after Step 3?
AFull user document
B'city' field value extracted
COnly the 'address' embedded document
DFiltered result set
💡 Hint
Look at the 'After Step 3' column for 'current_document' in variable_tracker.
If a user document has no 'address' field, what will happen during the query?
AIt will be skipped (not matched)
BIt will cause an error
CIt will match the query
DIt will update the document
💡 Hint
Refer to key_moments about missing 'address' field and execution_table steps 2 and 3.
Concept Snapshot
Dot notation accesses fields inside embedded documents.
Syntax: 'parent.child' (e.g., 'address.city').
Used in queries and updates to target nested fields.
If embedded document missing, condition is false.
Helps filter or modify nested data easily.
Full Transcript
Dot notation in MongoDB lets you access or update fields inside embedded documents by writing the parent field name, a dot, then the child field name. For example, to find users living in Boston, you write a query with 'address.city' equal to 'Boston'. The database looks inside each user's 'address' embedded document and checks the 'city' field. If the city matches, the document is returned. If a document has no 'address' field, it is skipped because the condition cannot be met. This way, dot notation helps you work with nested data easily and precisely.