MongoDB $gte Operator

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 4 Examples
Comparison

What You’ll Learn

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.

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.

📝 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:

$match{ age: { $gte: 21 } } (filters documents)
$project{ $gte: [ "$score", 70 ] } (returns boolean)
$cond → use expression form as the if condition

⚡ Quick Reference

QuestionAnswer
Operator typeComparison operator (query + expression)
Query syntax{ field: { $gte: value } }
Expression syntax{ $gte: [ expr1, expr2 ] }
Includes equals?Yes — use $gt to exclude
Expression outputtrue or false
Common stages$match, $project, $cond
$match filter
{
  age: { $gte: 21 }
}

Age 21 or older

Expression
{
  $gte: [
    "$score",
    70
  ]
}

Returns true/false

Field vs field
{
  $gte: [
    "$actual",
    "$expected"
  ]
}

Meets minimum check

find()
db.orders.find({
  quantity: { $gte: 10 }
})

Works in find too

Examples Gallery

Walk through sample student data, filter by minimum age with $match, and compare fields with the expression form.

📚 Filter by Minimum Age

Use a students collection and find everyone aged 21 or older with $match.

Sample Input Documents

Suppose you have a students collection with name and age fields:

mongosh
[
  { "_id": ObjectId("609c26812e9274a86871bc6a"), "name": "Alice", "age": 22 },
  { "_id": ObjectId("609c26812e9274a86871bc6b"), "name": "Bob", "age": 20 },
  { "_id": ObjectId("609c26812e9274a86871bc6c"), "name": "Charlie", "age": 25 }
]

Example 1 — $gte in a $match Stage

Find students who are 21 years old or older:

mongosh
db.students.aggregate([
  {
    $match: {
      age: { $gte: 21 }
    }
  }
])

How It Works

  • Alice (22) and Charlie (25) are greater than or equal to 21, so they pass the filter.
  • Bob (20) is excluded because 20 is less than 21.
  • If a student were exactly 21, they would be included — that is the key difference from $gt.

📈 Practical Patterns

Use the expression form in find(), add boolean flags, and power conditional logic.

Example 2 — $gte in a find() Query

Filter orders with quantity of 10 or more:

mongosh
db.orders.find({
  quantity: { $gte: 10 }
})

How It Works

$gte in find() uses the same query form as $match. It is ideal for minimum quantity, minimum price, and “on or after” date filters.

Example 3 — Add a Boolean Field with $project

Flag students who passed with a score of 70 or above:

mongosh
db.students.aggregate([
  {
    $project: {
      name: 1,
      score: 1,
      passed: {
        $gte: [ "$score", 70 ]
      }
    }
  }
])

How It Works

A score of exactly 70 returns true because $gte includes equals. With $gt, a score of 70 would return false.

Example 4 — $gte Inside $cond

Assign an age category based on whether someone is 18 or older:

mongosh
db.students.aggregate([
  {
    $project: {
      name: 1,
      age: 1,
      category: {
        $cond: [
          { $gte: [ "$age", 18 ] },
          "Adult",
          "Minor"
        ]
      }
    }
  }
])

How It Works

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.

🚀 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.

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.

💡 Best Practices

✅ Do

  • 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)

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
📝 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.

Continue the Operator Series

Move on to $hour for extracting hours from dates, or review $gt for strictly greater-than comparisons.

Next: $hour →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful