Challenge - 5 Problems
MongoDB Document Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What does this MongoDB document look like after insertion?
Consider the following MongoDB insert operation:
What will the stored document look like when retrieved?
db.users.insertOne({ name: "Alice", age: 30, hobbies: ["reading", "hiking"] })What will the stored document look like when retrieved?
MongoDB
db.users.findOne({ name: "Alice" })Attempts:
2 left
💡 Hint
Remember MongoDB automatically adds an _id field and preserves data types.
✗ Incorrect
MongoDB stores documents with an automatic _id field of type ObjectId unless specified. The age remains a number, and hobbies is stored as an array.
🧠 Conceptual
intermediate1:30remaining
How does MongoDB store nested data?
Which of the following best describes how MongoDB stores nested data inside documents?
Attempts:
2 left
💡 Hint
Think about how JSON objects can contain other objects.
✗ Incorrect
MongoDB stores nested data as embedded documents inside the main document, allowing hierarchical data representation.
📝 Syntax
advanced2:30remaining
Which MongoDB query correctly updates a nested field?
Given a document structure:
Which query correctly updates the city to "LA"?
{ name: "Bob", address: { city: "NY", zip: 10001 } }Which query correctly updates the city to "LA"?
Attempts:
2 left
💡 Hint
Use dot notation with $set to update nested fields.
✗ Incorrect
Option C uses the correct $set operator with dot notation to update the nested city field without overwriting the entire address.
❓ optimization
advanced3:00remaining
How to optimize queries on nested document fields?
You have a collection with documents containing nested fields like:
Which approach best improves query performance filtering by user name?
{ user: { name: "Eve", age: 25 }, status: "active" }Which approach best improves query performance filtering by user name?
Attempts:
2 left
💡 Hint
Indexes on fields used in queries speed up searches.
✗ Incorrect
Creating an index on user.name allows MongoDB to quickly find documents by that nested field without scanning all documents.
🔧 Debug
expert3:00remaining
Why does this MongoDB query return no results?
Given documents:
Which query will NOT return this document?
Options:
A) db.collection.find({ "details.age": 40 })
B) db.collection.find({ details: { age: 40, city: "Boston" } })
C) db.collection.find({ details: { city: "Boston", age: 40 } })
D) db.collection.find({ "details.city": "Boston" })
{ name: "Sam", details: { age: 40, city: "Boston" } }Which query will NOT return this document?
Options:
A) db.collection.find({ "details.age": 40 })
B) db.collection.find({ details: { age: 40, city: "Boston" } })
C) db.collection.find({ details: { city: "Boston", age: 40 } })
D) db.collection.find({ "details.city": "Boston" })
Attempts:
2 left
💡 Hint
Exact matches on embedded documents require the same field order.
✗ Incorrect
MongoDB matches embedded documents exactly including field order. Option A has different order and returns no results. Option A matches the document and returns the document. Therefore, option A is correct as NOT returning results.