0
0
MongoDBquery~20 mins

Document model mental model (JSON/BSON) in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Document Model Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this MongoDB find query?

Consider a collection users with documents like:

{ "name": "Alice", "age": 30, "hobbies": ["reading", "hiking"] }

What will this query return?

db.users.find({ "hobbies": "hiking" })
MongoDB
db.users.find({ "hobbies": "hiking" })
A[{ "name": "Alice", "age": 30, "hobbies": ["reading", "hiking"] }]
B[]
C[{ "name": "Alice", "age": 30 }]
D[{ "hobbies": "hiking" }]
Attempts:
2 left
💡 Hint

Think about how MongoDB matches array fields with a value.

🧠 Conceptual
intermediate
1:30remaining
Which BSON data type is used to store a date?

In MongoDB's BSON format, which data type stores date and time values?

ATimestamp
BObjectId
CDate
DString
Attempts:
2 left
💡 Hint

It is a special BSON type different from a string.

📝 Syntax
advanced
2:00remaining
Which option correctly inserts a nested document in MongoDB?

You want to insert a document with a nested address field. Which command is correct?

MongoDB
db.customers.insertOne({ name: "John", address: { city: "NY", zip: "10001" } })
Adb.customers.insertOne({ name: "John", address: { city: "NY", zip: "10001" } })
Bdb.customers.insertOne({ name: "John", address: [ city: "NY", zip: "10001" ] })
Cdb.customers.insertOne({ name: "John", address: ( city: "NY", zip: "10001" ) })
Ddb.customers.insertOne({ name: "John", address: "city: NY, zip: 10001" })
Attempts:
2 left
💡 Hint

Remember nested documents use curly braces, not brackets or parentheses.

optimization
advanced
2:30remaining
Which index type improves search on nested fields in MongoDB?

You want to speed up queries filtering by a nested field address.city. Which index type should you create?

ACreate a multikey index on <code>address.city</code>
BCreate a compound index on <code>address.city</code> and <code>address.zip</code>
CCreate a single field index on <code>address</code>
DCreate a single field index on <code>address.city</code>
Attempts:
2 left
💡 Hint

Think about indexing a specific nested field.

🔧 Debug
expert
3:00remaining
Why does this MongoDB query return no results?

Given documents with a field tags as an array of strings, why does this query return no documents?

db.posts.find({ tags: { $eq: ["mongodb", "database"] } })
ABecause $eq does not match arrays, only single values
BBecause the query looks for exact array match, but documents have tags in different order
CBecause $eq requires a nested query with $all for arrays
DBecause the field name is incorrect; it should be 'tag' not 'tags'
Attempts:
2 left
💡 Hint

Think about how MongoDB compares arrays in queries.