0
0
MongoDBquery~20 mins

Implicit AND with multiple conditions in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MongoDB Implicit AND Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Find documents matching multiple conditions with implicit AND
Given a collection products with documents containing category and price, what is the output of this query?

db.products.find({ category: "books", price: { $lt: 20 } })

Assume the collection has:
{"category": "books", "price": 15}
{"category": "books", "price": 25}
{"category": "electronics", "price": 15}
MongoDB
db.products.find({ category: "books", price: { $lt: 20 } })
A[{"category": "books", "price": 25}]
B[{"category": "books", "price": 15}]
C[{"category": "electronics", "price": 15}]
D[]
Attempts:
2 left
💡 Hint
Remember that specifying multiple fields in the query object means all conditions must be true.
🧠 Conceptual
intermediate
1:30remaining
Understanding implicit AND in MongoDB queries
Which statement best describes how MongoDB treats multiple conditions inside a single query object?
AMongoDB treats multiple conditions as an implicit OR, returning documents matching any condition.
BMongoDB ignores all but the first condition in the query object.
CMongoDB requires explicit $and operator to combine multiple conditions.
DMongoDB treats multiple conditions as an implicit AND, returning documents matching all conditions.
Attempts:
2 left
💡 Hint
Think about how multiple fields in a JSON object combine logically.
📝 Syntax
advanced
2:00remaining
Identify the invalid MongoDB query with multiple conditions
Which of the following MongoDB queries will cause a syntax error or fail to run?
Adb.collection.find({ age: { $gt: 18 }, status: { $in: ["active", "pending"] } })
Bdb.collection.find({ $and: [{ age: { $gt: 18 } }, { status: "active" }] })
Cdb.collection.find({ age: { $gt: 18 }, $or: { status: "active" } })
Ddb.collection.find({ age: { $gt: 18 }, status: "active" })
Attempts:
2 left
💡 Hint
Check if the query mixes implicit AND with explicit $or incorrectly.
optimization
advanced
2:00remaining
Optimizing queries with multiple conditions
You want to find documents where status is "active" and score is greater than 50. Which query is more efficient in MongoDB?
Adb.collection.find({ status: "active", score: { $gt: 50 } })
Bdb.collection.find({ $and: [{ status: "active" }, { score: { $gt: 50 } }] })
Cdb.collection.find({ $or: [{ status: "active" }, { score: { $gt: 50 } }] })
Ddb.collection.find({ status: { $eq: "active" }, score: { $gt: 50 } })
Attempts:
2 left
💡 Hint
Consider how MongoDB processes implicit AND vs explicit $and.
🔧 Debug
expert
2:30remaining
Why does this MongoDB query return no results?
Given the collection users with documents:
{"name": "Alice", "age": 30, "city": "NY"}
{"name": "Bob", "age": 35, "city": "LA"}

Why does this query return no documents?

db.users.find({ age: { $gt: 20 }, age: { $lt: 28 } })
ABecause MongoDB does not support multiple conditions on the same field in one query object; the second overwrites the first.
BBecause no user has age greater than 20 and less than 28 at the same time.
CBecause the query syntax is invalid and causes an error.
DBecause the collection is empty.
Attempts:
2 left
💡 Hint
Check how JSON objects handle duplicate keys.