0
0
MongoDBquery~20 mins

$gt and $gte for greater than in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Greater Than 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 } })
AReturns all users with age less than or equal to 30
BReturns all users with age greater than or equal to 30
CReturns all users with age less than 30
DReturns all users with age strictly greater than 30
Attempts:
2 left
💡 Hint
Remember, $gt means strictly greater than, not including the value.
query_result
intermediate
2:00remaining
Find documents with age greater than or equal to 30
Which MongoDB query returns all users with age 30 or older?
MongoDB
db.users.find({ age: { $gte: 30 } })
AReturns users with age greater than or equal to 30
BReturns users with age strictly greater than 30
CReturns users with age less than 30
DReturns users with age less than or equal to 30
Attempts:
2 left
💡 Hint
Think about including the value 30 itself.
🧠 Conceptual
advanced
2:00remaining
Difference between $gt and $gte
Which statement correctly describes the difference between $gt and $gte in MongoDB queries?
A<code>$gt</code> excludes the value specified, <code>$gte</code> includes it
B<code>$gt</code> includes the value specified, <code>$gte</code> excludes it
CBoth <code>$gt</code> and <code>$gte</code> exclude the value specified
DBoth <code>$gt</code> and <code>$gte</code> include the value specified
Attempts:
2 left
💡 Hint
Think about whether the boundary value is included or not.
📝 Syntax
advanced
2:00remaining
Identify the valid MongoDB query syntax for greater than
Which of the following MongoDB queries is syntactically correct to find documents where score is greater than 50?
Adb.collection.find({ score > 50 })
Bdb.collection.find({ score: $gt 50 })
Cdb.collection.find({ score: { $gt: 50 } })
Ddb.collection.find({ score: { gt: 50 } })
Attempts:
2 left
💡 Hint
Remember the syntax for operators in MongoDB queries uses $ and colon.
optimization
expert
3:00remaining
Optimizing queries using $gt and $gte with indexes
You have a large collection with an index on the price field. Which query will best use the index to find documents with price greater than or equal to 100?
Adb.products.find({ price: { $gt: 99 } })
Bdb.products.find({ price: { $gte: 100 } })
Cdb.products.find({ price: { $gte: 100 }, price: { $lt: 200 } })
Ddb.products.find({ price: { $gt: 100 } })
Attempts:
2 left
💡 Hint
Think about the exact boundary value and index usage.