0
0
MongoDBquery~20 mins

Query filter syntax in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Query Filter Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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 } })
Adb.users.find({ age: { $gt: 30 } })
Bdb.users.find({ age: { $lt: 30 } })
Cdb.users.find({ age: { $gte: 30 } })
Ddb.users.find({ age: 30 })
Attempts:
2 left
💡 Hint
Use $gt to find values greater than a number.
query_result
intermediate
2: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/ })
Adb.users.find({ name: /^A/ })
Bdb.users.find({ name: { $regex: 'A$' } })
Cdb.users.find({ name: { $regex: '^A' } })
Ddb.users.find({ name: { $regex: 'A' } })
Attempts:
2 left
💡 Hint
Use a regular expression to match the start of the string.
📝 Syntax
advanced
2: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 } })
Adb.products.find({ price: { $gte: 50, $lte: 100 } })
Bdb.products.find({ price: { $gt: 50, $lt: 100 } })
Cdb.products.find({ price: { $lt: 100, $gt: 50 } })
Ddb.products.find({ price: { $lt: 100 } $gt: 50 })
Attempts:
2 left
💡 Hint
Check for missing commas or misplaced braces.
optimization
advanced
2: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'] } })
Adb.users.find({ $or: [ { status: 'active' }, { status: 'pending' } ] })
Bdb.users.find({ status: 'active' || 'pending' })
Cdb.users.find({ status: { $in: ['active', 'pending'] } })
Ddb.users.find({ status: { $or: ['active', 'pending'] } })
Attempts:
2 left
💡 Hint
Use $in operator for multiple possible values in one field.
🧠 Conceptual
expert
2:00remaining
Understanding query filter behavior with missing fields
What will the query db.orders.find({ shippedDate: { $exists: false } }) return?
ADocuments where the shippedDate field exists and is null
BDocuments where the shippedDate field does not exist
CDocuments where the shippedDate field is missing or null
DDocuments where the shippedDate field exists and has any value
Attempts:
2 left
💡 Hint
The $exists operator checks if a field is present in the document.