Challenge - 5 Problems
Nested Document Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Insert a document with nested address
Given the following insert command, what will be the content of the inserted document in the collection?
MongoDB
db.users.insertOne({name: "Alice", age: 30, address: {street: "123 Maple St", city: "Springfield", zip: "01101"}})Attempts:
2 left
💡 Hint
Nested documents are stored as embedded objects inside the main document.
✗ Incorrect
The insertOne command stores the nested 'address' as an embedded document with all its fields intact.
❓ query_result
intermediate2:00remaining
Insert with multiple nested levels
What will be the structure of the document after this insert?
MongoDB
db.orders.insertOne({orderId: 101, customer: {name: "Bob", contact: {email: "bob@example.com", phone: "123-4567"}}, items: [{product: "Pen", qty: 10}, {product: "Notebook", qty: 5}]})Attempts:
2 left
💡 Hint
Nested objects can have multiple levels and arrays can contain objects.
✗ Incorrect
The 'customer' field contains a nested 'contact' document, and 'items' is an array of nested documents.
📝 Syntax
advanced2:00remaining
Identify the syntax error in nested document insert
Which option contains a syntax error that will prevent the document from being inserted?
MongoDB
db.products.insertOne({name: "Chair", specs: {color: "red", weight: 5, dimensions: {width: 40, height: 90}}})Attempts:
2 left
💡 Hint
Check for matching braces and parentheses.
✗ Incorrect
Option C is missing the closing brace and parenthesis, causing a syntax error.
🔧 Debug
advanced2:00remaining
Why does this nested insert fail?
This insert command fails. What is the cause?
MongoDB
db.employees.insertOne({name: "Eve", details: {age: 28, skills: ["JavaScript", "MongoDB"], projects: {current: "Website", completed: 3}})Attempts:
2 left
💡 Hint
Count the opening and closing braces carefully.
✗ Incorrect
The main document is missing a closing brace at the end, causing the insert to fail.
❓ optimization
expert3:00remaining
Optimizing nested document insert for large arrays
You want to insert a document with a large array of nested documents efficiently. Which approach is best?
Attempts:
2 left
💡 Hint
MongoDB handles nested arrays well if inserted in one document.
✗ Incorrect
Inserting the entire nested array at once is more efficient than multiple updates or splitting into many documents.