0
0
MongoDBquery~20 mins

Embedded documents (nested objects) in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Embedded Documents Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Find documents with a nested field value
Given a collection users where each document has an embedded address object with fields city and zip, which query returns all users living in the city 'Springfield'?
MongoDB
db.users.find({"address.city": "Springfield"})
Adb.users.find({"address": {"city": "Springfield"}})
Bdb.users.find({address: {city: "Springfield"}})
Cdb.users.find({"address.city": "Springfield"})
Ddb.users.find({city: "Springfield"})
Attempts:
2 left
💡 Hint
Use dot notation to query nested fields inside embedded documents.
query_result
intermediate
2:00remaining
Retrieve nested array elements in embedded documents
Consider a collection orders where each document has an embedded array items with objects containing product and quantity. Which query returns all orders that include an item with product equal to 'Pen'?
MongoDB
db.orders.find({"items.product": "Pen"})
Adb.orders.find({product: "Pen"})
Bdb.orders.find({items: {product: "Pen"}})
Cdb.orders.find({"items": {"product": "Pen"}})
Ddb.orders.find({"items.product": "Pen"})
Attempts:
2 left
💡 Hint
Use dot notation to query fields inside objects within arrays.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in nested document update
Which update command correctly sets the nested field profile.contact.email to 'user@example.com' for the document with _id 1?
MongoDB
db.users.updateOne({_id: 1}, {$set: {"profile.contact.email": "user@example.com"}})
A)}}"moc.elpmaxe@resu" :"liame.tcatnoc.eliforp"{ :tes${ ,}1 :di_{(enOetadpu.sresu.bd
Bdb.users.updateOne({_id: 1}, {$set: {"profile.contact.email": "user@example.com"}})
Cdb.users.updateOne({_id: 1}, {$set: {profile: {contact: {email: "user@example.com"}}}})
Ddb.users.updateOne({_id: 1}, {$set: {"profile": {"contact": {"email": "user@example.com"}}}})
Attempts:
2 left
💡 Hint
Use quotes around the full nested field path when using dot notation in update operators.
optimization
advanced
2:00remaining
Optimize query on nested fields with indexes
You have a collection products with embedded documents specs containing weight and color. Which index will best optimize queries filtering by specs.color?
A{"specs.color": 1}
B{"specs": 1}
C{"color": 1}
D{"specs.weight": 1}
Attempts:
2 left
💡 Hint
Indexes on nested fields use dot notation for the field name.
🧠 Conceptual
expert
2:00remaining
Understanding document size limits with embedded documents
MongoDB has a maximum document size of 16MB. Which statement about using embedded documents is true?
AEmbedding large nested documents can cause the document to exceed the 16MB limit, so large data should be referenced instead.
BEmbedded documents do not count towards the 16MB document size limit.
CMongoDB automatically splits large embedded documents into multiple documents to avoid size limits.
DThe 16MB limit applies only to top-level fields, not to embedded documents.
Attempts:
2 left
💡 Hint
Consider how document size limits affect embedded data storage.