$gte (Greater Than or Equal)
Last updated: 2026-10-09
$gte (Greater Than or Equal)
$gte is the expression-form greater-than-or-equal comparison. It takes two arguments and returns true when the first is greater than or equal to the second. It is used for threshold checks and range filtering, such as keeping products whose sales meet a guaranteed minimum. The expression syntax is { $gte: [expr1, expr2] }, unlike the query operator { field: { $gte: value } }. Comparisons follow BSON type ordering, and unlike $gt it returns true when the values are equal.
| Category | Set, Condition & Conversion |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
{ $gte: [ <expression1>, <expression2> ] }
⚙️ Parameters
| expression 1 | The first expression to compare. |
|---|---|
| expression 2 | The second expression to compare. |
Returns:true when the first is greater than or equal to the second, false otherwise
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// $gte: check whether sales meet the target
db.products.aggregate([
{ $project: {
qualified: { $gte: ['$sales', '$target'] }
} }
])
Output:
{ '_id': 1, 'qualified': true }
{ '_id': 2, 'qualified': false }
📌 Notes
- Equality also returns true, the key difference from $gt
- The expression and query forms are written differently
- Comparisons follow the BSON type ordering
🏷️ Related Tags
💡 Related Cases
More hands-on cases coming soon.
📚 Related Tutorials
❓ FAQ
QWhat is the difference between $gte and $gt?
A$gte includes equality while $gt is strictly greater.
QCan $gte compare dates?
AYes, dates compare by their chronological order.
QDo both $gte arguments have to be numbers?
ANo — any types compare by the BSON type ordering.