Challenge - 5 Problems
Master of Combining Comparison Operators
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find documents with age between 25 and 35 inclusive
Given a collection
users with documents containing an age field, which query returns all users whose age is between 25 and 35 inclusive?MongoDB
db.users.find({ age: { $gte: 25, $lte: 35 } })Attempts:
2 left
💡 Hint
Use $gte and $lte together inside the same object for the field.
✗ Incorrect
Option C correctly combines $gte and $lte inside the same object for the age field, returning ages from 25 to 35 inclusive. Option C excludes 25 and 35. Option C is invalid because the same field cannot appear twice in the same object. Option C uses projection syntax incorrectly.
❓ query_result
intermediate2:00remaining
Find documents where score is less than 50 or greater than 90
Which MongoDB query returns documents where the
score field is either less than 50 or greater than 90?MongoDB
db.scores.find({ $or: [ { score: { $lt: 50 } }, { score: { $gt: 90 } } ] })Attempts:
2 left
💡 Hint
Use $or to combine conditions that can be true alternatively.
✗ Incorrect
Option D correctly uses $or to find documents where score is less than 50 or greater than 90. Option D tries to combine $lt and $gt on the same field in one object, which is impossible to satisfy. Option D uses projection syntax incorrectly. Option D uses $and which requires both conditions to be true simultaneously, which is impossible.
📝 Syntax
advanced2:00remaining
Identify the syntax error in this query combining comparison operators
Which option contains a syntax error when trying to find documents with
price between 100 and 200?MongoDB
db.products.find({ price: { $gte: 100, $lte: 200 } })Attempts:
2 left
💡 Hint
Check if the same field appears twice in the same object.
✗ Incorrect
Option B is invalid syntax because the field 'price' appears twice in the same object, which is not allowed in MongoDB queries. Options A, B, and C are syntactically valid. Option B includes an empty projection which is allowed. Option B has a trailing comma which is allowed in JavaScript objects.
❓ optimization
advanced2:00remaining
Optimize query to find documents with age not between 20 and 30
Which query is the most efficient and correct way to find documents where
age is NOT between 20 and 30 inclusive?Attempts:
2 left
💡 Hint
Use $or to combine conditions that exclude the range.
✗ Incorrect
Option A correctly uses $or to find ages less than 20 or greater than 30. Option A is invalid because $not cannot combine multiple operators inside one object like that. Option A is invalid syntax; $ne expects a value, not a range. Option A is impossible because age cannot be less than 20 and greater than 30 simultaneously.
🧠 Conceptual
expert2:00remaining
Understanding behavior of combined comparison operators in MongoDB
Consider the query
db.collection.find({ value: { $gt: 10, $lt: 20 } }). Which statement about this query is true?Attempts:
2 left
💡 Hint
Think about how MongoDB interprets multiple operators inside one field object.
✗ Incorrect
Option A is correct because MongoDB treats multiple comparison operators inside the same field object as an AND condition. Option A is incorrect because $or is needed for OR logic. Option A is incorrect because $gt and $lt exclude the boundary values. Option A is incorrect because combining multiple operators inside one object is valid syntax.