0
0
MongoDBquery~5 mins

Embedded documents (nested objects) in MongoDB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an embedded document in MongoDB?
An embedded document is a document stored inside another document as a nested object. It helps group related data together in one place.
Click to reveal answer
beginner
How do you represent a nested object in a MongoDB document?
You use curly braces inside a field to create a nested object. For example: { "address": { "city": "Paris", "zip": "75000" } }
Click to reveal answer
intermediate
Why use embedded documents instead of separate collections?
Embedded documents keep related data together, making it faster to read and easier to manage small related data without extra queries.
Click to reveal answer
intermediate
How do you query a field inside an embedded document in MongoDB?
Use dot notation to access nested fields. For example: db.collection.find({ "address.city": "Paris" }) finds documents where city inside address is Paris.
Click to reveal answer
beginner
Can embedded documents contain arrays in MongoDB?
Yes, embedded documents can have arrays as values, and those arrays can contain objects or simple values.
Click to reveal answer
What does an embedded document in MongoDB allow you to do?
AEncrypt data automatically
BCreate a new database
CRun SQL queries
DStore related data inside a single document
How do you access a nested field 'city' inside 'address' in a MongoDB query?
Aaddress->city
Baddress_city
Caddress.city
Dcity.address
Which of these is a correct example of an embedded document?
A{ name: 'John', address: { city: 'NY', zip: '10001' } }
B{ name: 'John', city: 'NY', zip: '10001' }
C[ { city: 'NY' }, { zip: '10001' } ]
Dname: 'John', address: 'NY'
Why might you choose embedded documents over references in MongoDB?
ATo increase database size
BTo reduce the number of queries needed to get related data
CTo separate unrelated data
DTo use SQL joins
Can embedded documents contain arrays in MongoDB?
AYes, arrays can be inside embedded documents
BNo, arrays are not allowed
COnly arrays of numbers are allowed
DOnly arrays of strings are allowed
Explain what embedded documents are in MongoDB and why they are useful.
Think about how you might store an address inside a user profile.
You got /3 concepts.
    Describe how to query a nested field inside an embedded document in MongoDB.
    Remember the format: 'field.subfield' in the query.
    You got /3 concepts.