The $gte operator checks whether one value is greater than or equal to another. Use it in $match to filter documents at or above a threshold, or in expression stages like $project and $cond to compare fields and get a true/false result.
01
Greater or Equal
Left value ≥ right value.
02
Two Syntax Forms
Query filter vs expression.
03
$match Stage
Filter at minimum value.
04
Boolean Output
true or false in $project.
05
Use Cases
Age, dates, quantities.
06
vs $gt
Includes equal values.
Fundamentals
Definition and Usage
In MongoDB, the $gte operator tests whether one value is greater than or equal to another. In a $match stage, { age: { $gte: 21 } } filters documents where age is 21 or higher. In an aggregation expression, { $gte: [ "$score", 70 ] } returns true or false for each document. It pairs naturally with $lte for range queries and with $gt when you need to exclude the boundary value.
💡
Beginner Tip
$gte includes the threshold value. { age: { $gte: 21 } } matches age 21, 22, 25, and so on. Use $gt when you need strictly greater than and want to exclude the boundary.
Foundation
📝 Syntax
$gte has two forms depending on where you use it:
Query form (in $match or find filters)
mongosh
{ field: { $gte: <value> } }
Aggregation expression form (in $project, $cond, etc.)
mongosh
{ $gte: [ <expression1>, <expression2> ] }
Syntax Rules
Query form — filters documents where the field is greater than or equal to the given value.
Expression form — compares two expressions and returns true or false.
Includes equals — a value exactly equal to the threshold matches.
Works with numbers, dates, and strings (BSON comparison order).
Use expression form inside $project, $addFields, $cond, and $filter.
💡 Query Form vs Expression Form
Know which form to use based on your pipeline stage:
When $gte returns true (age ≥ 18), $cond outputs "Adult". A student exactly 18 is classified as an adult. Combine $gte with $lte for age ranges.
Applications
🚀 Use Cases
Age filtering — find people at or above a minimum age like 18 or 21.
Date comparison — select records on or after a specific date with { createdAt: { $gte: date } }.
Quantity analysis — identify inventory or orders meeting a minimum threshold.
Passing grades — use in $cond when the boundary score should count as passing.
🧠 How $gte Works
1
MongoDB reads the operands
In $match, it checks a field against a minimum. In expressions, it evaluates two operands like "$age" and 21.
Input
2
$gte compares values
MongoDB checks whether the first value is greater than or equal to the second using BSON comparison rules.
Compare
3
Result is applied in the pipeline
In $match, matching documents pass through. In expressions, true or false is stored in the output field.
Output
=
🔍
Filtered or flagged data
You get documents at or above a threshold or boolean fields ready for conditional logic.
Wrap Up
Conclusion
The $gte operator is a core comparison tool in MongoDB. It powers minimum-threshold filtering in $match and find(), boolean field creation in $project, and conditional branching in $cond — especially when the boundary value should be included.
For beginners, remember two forms: query form { field: { $gte: value } } filters documents, and expression form { $gte: [ expr1, expr2 ] } returns true or false. Use $gt when equal values should be excluded from the result.
Use query form in $match and find() for minimum-threshold filtering
Use expression form in $project and $cond
Prefer $gte when the boundary value should match
Combine with $lte for inclusive range queries
Index fields used in $gte filters for better performance
❌ Don’t
Confuse $gte with $gt when equals matters
Use expression form inside $match without $expr
Compare different BSON types and expect reliable results
Forget that $gte includes the threshold value
Use $gte when you need strict greater-than only (use $gt)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about $gte
Use these points when writing greater-than-or-equal comparisons in MongoDB.
5
Core concepts
🔢01
Greater or Equal
Includes threshold.
Purpose
📝02
Two Forms
Query filter vs expression.
Syntax
🛠03
$match Filter
At-or-above docs.
Usage
🔍04
Min Thresholds
Age, score, quantity.
Use case
⚠05
Not $gt
Equals included.
Edge case
❓ Frequently Asked Questions
$gte checks whether one value is greater than or equal to another. In query filters it matches documents where a field meets or exceeds a threshold. In aggregation expressions it returns true or false when comparing two expressions.
Query form: { field: { $gte: value } }. Aggregation expression form: { $gte: [ <expression1>, <expression2> ] }. There is no shorthand — you must use the explicit $gte operator.
$gte includes values equal to the threshold. $gt is strictly greater than and excludes equals. For example, { score: { $gte: 80 } } matches 80, but { score: { $gt: 80 } } does not.
In $match, $gte filters documents at or above the threshold. In $project or $addFields, $gte compares two expressions and adds a boolean field (true/false) to each document.
Yes. $gte uses BSON comparison order. Dates compare chronologically, numbers numerically, and strings lexicographically. Ensure both operands are the same type for predictable results.