0
0
MongoDBquery~20 mins

Rows vs documents thinking in MongoDB - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Document Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding document structure vs row structure
In MongoDB, which statement best describes how data is stored compared to a traditional SQL row?
AData is stored as flexible documents that can contain nested arrays and objects, unlike fixed columns in SQL rows.
BData is stored strictly in tables with fixed columns and rows, similar to SQL databases.
CEach document in MongoDB must have the same fields and data types, just like SQL rows.
DMongoDB stores data only as key-value pairs without any nested structure.
Attempts:
2 left
💡 Hint
Think about how JSON-like documents allow more flexible data than rows.
query_result
intermediate
2:00remaining
Query result shape in MongoDB vs SQL
Given a MongoDB collection 'users' with documents containing nested 'address' objects, what will this query return? `db.users.find({"address.city": "Seattle"})`
MongoDB
db.users.find({"address.city": "Seattle"})
AOnly the 'address' subdocuments where city is 'Seattle', excluding other user data.
BAll user documents where the nested 'address' object has a 'city' field equal to 'Seattle'.
CAn error because nested fields cannot be queried in MongoDB.
DAll users regardless of city because nested queries are ignored.
Attempts:
2 left
💡 Hint
MongoDB allows querying nested fields using dot notation.
📝 Syntax
advanced
2:00remaining
Correct MongoDB query to update nested document field
Which of the following MongoDB update queries correctly sets the 'address.zip' field to '98101' for user with _id 123?
Adb.users.updateOne({_id: 123}, {$update: {"address.zip": "98101"}})
Bdb.users.updateOne({_id: 123}, {$set: {address: {zip: "98101"}}})
Cdb.users.updateOne({_id: 123}, {$set: {"address.zip": "98101"}})
Ddb.users.update({_id: 123}, {$set: {zip: "98101"}})
Attempts:
2 left
💡 Hint
Use dot notation inside $set to update nested fields.
optimization
advanced
2:00remaining
Optimizing queries on nested document fields
You have a large MongoDB collection with documents containing nested 'profile.age' fields. Which indexing strategy will best optimize queries filtering by 'profile.age'?
ACreate a single-field index on 'profile.age'.
BCreate a compound index on 'profile' and 'age' separately.
CCreate a text index on the entire document.
DNo index is needed because nested fields cannot be indexed.
Attempts:
2 left
💡 Hint
Indexes on nested fields use dot notation.
🔧 Debug
expert
3:00remaining
Diagnosing unexpected query results with nested documents
A developer runs this query on a MongoDB collection: `db.orders.find({"customer.address.city": "Boston"})` But it returns no results, even though some documents have 'customer' with nested 'address.city' equal to 'Boston'. What is the most likely cause?
AMongoDB does not support querying nested fields with dot notation.
BThe field name 'city' is case-sensitive and should be 'City' instead.
CThe query syntax is invalid because quotes are missing around the field name.
DThe 'customer' field is an array of objects, so dot notation does not match nested fields inside arrays without $elemMatch.
Attempts:
2 left
💡 Hint
Consider how nested arrays affect dot notation queries.