0
0
MongoDBquery~5 mins

$gt and $gte for greater than in MongoDB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the $gt operator do in MongoDB?

The $gt operator finds documents where the value of a field is greater than a specified value.

Click to reveal answer
beginner
How is $gte different from $gt in MongoDB?

$gte means greater than or equal to, so it includes the specified value itself, while $gt means strictly greater than.

Click to reveal answer
beginner
Write a MongoDB query to find all products with a price greater than 100.
{ price: { $gt: 100 } }
Click to reveal answer
beginner
Write a MongoDB query to find all users with age greater than or equal to 18.
{ age: { $gte: 18 } }
Click to reveal answer
beginner
If you want to include the value 50 in your search for values greater than or equal to 50, which operator should you use?

You should use $gte because it includes the value itself (50) and all values greater than 50.

Click to reveal answer
Which MongoDB operator finds documents where a field is strictly greater than a value?
A$gt
B$gte
C$lt
D$lte
What does { age: { $gte: 21 } } find?
ADocuments with age less than 21
BDocuments with age equal to 21 only
CDocuments with age greater than 21 only
DDocuments with age 21 or older
Which query finds products priced more than 50 but not including 50?
A{ price: { $gte: 50 } }
B{ price: { $gt: 50 } }
C{ price: { $lte: 50 } }
D{ price: { $lt: 50 } }
If you want to find all records with a score at least 75, which operator do you use?
A$gte
B$lt
C$gt
D$lte
True or False: $gt includes the value you compare against.
ATrue
BSometimes
CFalse
DDepends on data type
Explain the difference between $gt and $gte in MongoDB queries.
Think about whether the value you compare against is included or not.
You got /4 concepts.
    Write a MongoDB query to find all documents where the field 'score' is greater than or equal to 90.
    Use the $gte operator inside the field object.
    You got /4 concepts.