Challenge - 5 Problems
Query Filter Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find documents with age greater than 30
Given a collection
users with documents containing an age field, which query returns all users older than 30?MongoDB
db.users.find({ age: { $gt: 30 } })Attempts:
2 left
💡 Hint
Use $gt to find values greater than a number.
✗ Incorrect
The $gt operator filters documents where the field value is greater than the specified number. $gte includes the number itself, $lt is less than, and matching age: 30 finds exact matches.
❓ query_result
intermediate2:00remaining
Find documents with name starting with 'A'
Which query returns all documents where the
name field starts with the letter 'A'?MongoDB
db.users.find({ name: /^A/ })Attempts:
2 left
💡 Hint
Use a regular expression to match the start of the string.
✗ Incorrect
The regex /^A/ matches strings starting with 'A'. Option A is similar but uses $regex syntax. However, option A is the direct and correct syntax. Option A matches strings ending with 'A'. Option A matches strings containing 'A' anywhere.
📝 Syntax
advanced2:00remaining
Identify the syntax error in this query
Which option contains a syntax error in the MongoDB query filter?
MongoDB
db.products.find({ price: { $lt: 100, $gt: 50 } })Attempts:
2 left
💡 Hint
Check for missing commas or misplaced braces.
✗ Incorrect
Option D is missing a comma between the two operators inside the object, causing a syntax error. Options B, C, and D are syntactically correct.
❓ optimization
advanced2:00remaining
Optimize query to find users with status 'active' or 'pending'
Which query is the most efficient to find users whose
status is either 'active' or 'pending'?MongoDB
db.users.find({ status: { $in: ['active', 'pending'] } })Attempts:
2 left
💡 Hint
Use $in operator for multiple possible values in one field.
✗ Incorrect
Option C uses $in which is optimized for matching any value in the list. Option C works but is less concise. Option C is invalid syntax. Option C uses $or incorrectly inside a field.
🧠 Conceptual
expert2:00remaining
Understanding query filter behavior with missing fields
What will the query
db.orders.find({ shippedDate: { $exists: false } }) return?Attempts:
2 left
💡 Hint
The $exists operator checks if a field is present in the document.
✗ Incorrect
The query with $exists: false returns documents where the field is not present at all. It does not include documents where the field exists but is null.