MongoDB $lte Operator

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

What You’ll Learn

The $lte operator checks whether one value is less than or equal to another. Use it in $match to filter documents at or below a threshold, or in expression stages like $project and $cond to compare fields and get a true/false result.

01

Less or Equal

Left value ≤ right value.

02

Two Syntax Forms

Query filter vs expression.

03

Includes Equals

Boundary values match.

04

$match Stage

Filter at or below cap.

05

Use Cases

Ages, dates, caps.

06

vs $lt

Inclusive vs strict.

Definition and Usage

In MongoDB, the $lte operator tests whether one value is less than or equal to another. In a $match stage, { age: { $lte: 20 } } filters documents where age is 20 or younger. In an aggregation expression, { $lte: [ "$price", 100 ] } returns true or false for each document. It pairs naturally with $gte for inclusive range queries.

💡
Beginner Tip

The key difference from $lt: $lte includes values equal to the threshold. { age: { $lte: 20 } } matches age 20; { age: { $lt: 20 } } does not.

📝 Syntax

$lte has two forms depending on where you use it:

Query form (in $match or find filters)

mongosh
{ field: { $lte: <value> } }

Aggregation expression form (in $project, $cond, etc.)

mongosh
{ $lte: [ <expression1>, <expression2> ] }

Syntax Rules

  • Query form — filters documents where the field is less than or equal to the given value.
  • Expression form — compares two expressions and returns true or false.
  • Includes equals — values equal to the threshold match (unlike $lt).
  • Works with numbers, dates, and strings (BSON comparison order).
  • Use expression form inside $project, $addFields, $cond, and $filter.

💡 $lte vs $lt

{ age: { $lte: 20 } } → matches 20, 18, 15 …
{ age: { $lt: 20 } } → matches 18, 15 … but not 20
$match{ age: { $lte: 20 } } (filters documents)
$project{ $lte: [ "$price", 100 ] } (returns boolean)

⚡ Quick Reference

QuestionAnswer
Operator typeComparison operator (query + expression)
Query syntax{ field: { $lte: value } }
Expression syntax{ $lte: [ expr1, expr2 ] }
Includes equals?Yes — boundary values match
Expression outputtrue or false
Common stages$match, $project, $cond
$match filter
{
  age: { $lte: 20 }
}

Age 20 or younger

Expression
{
  $lte: [
    "$price",
    100
  ]
}

Returns true/false

Date cap
{
  createdAt: {
    $lte: ISODate(
      "2024-12-31"
    )
  }
}

On or before date

find()
db.orders.find({
  quantity: { $lte: 5 }
})

Works in find too

Examples Gallery

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

📚 Filter by Maximum Age

Use a students collection and find everyone aged 20 or younger with $match.

Sample Input Documents

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

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

Example 1 — $lte in a $match Stage

Find students who are 20 years old or younger:

mongosh
db.students.aggregate([
  {
    $match: {
      age: { $lte: 20 }
    }
  }
])

How It Works

  • Alice (20) matches because 20 is less than or equal to 20.
  • Charlie (18) matches because 18 ≤ 20.
  • Bob (25) is excluded because 25 exceeds the threshold.
  • With $lt instead, Alice (exactly 20) would not match.

📈 Practical Patterns

Use the expression form in find(), add boolean flags, and build inclusive ranges.

Example 2 — $lte in a find() Query

Find orders with quantity of 5 or fewer:

mongosh
db.orders.find({
  quantity: { $lte: 5 }
})

How It Works

$lte in find() uses the same query form as $match. It is ideal for maximum quantity, price caps, and “on or before” date filters.

Example 3 — Add a Boolean Field with $project

Flag products priced at $100 or below on every document:

mongosh
db.products.aggregate([
  {
    $project: {
      name: 1,
      price: 1,
      isAffordable: {
        $lte: [ "$price", 100 ]
      }
    }
  }
])

How It Works

A price of exactly 100 returns true because $lte includes equals. With $lt, a price of 100 would return false.

Example 4 — $lte Inside $cond

Label inventory as “low stock” when quantity is 10 or below:

mongosh
db.inventory.aggregate([
  {
    $project: {
      item: 1,
      quantity: 1,
      status: {
        $cond: [
          { $lte: [ "$quantity", 10 ] },
          "low stock",
          "in stock"
        ]
      }
    }
  }
])

How It Works

When $lte returns true (quantity ≤ 10), $cond outputs "low stock". An item with exactly 10 units is flagged as low stock.

Bonus — Inclusive Range with $gte and $lte

Filter students between 18 and 25 years old, including both boundaries:

mongosh
db.students.aggregate([
  {
    $match: {
      age: { $gte: 18, $lte: 25 }
    }
  }
])

// Alice (20)  → included
// Bob (25)    → included (25 ≤ 25)
// Charlie (18) → included (18 ≥ 18)

How It Works

Pair $gte and $lte for inclusive ranges. Both boundary values are included. Use $gt and $lt when you need exclusive boundaries.

🚀 Use Cases

  • Age and eligibility caps — find users at or below a maximum age or spending limit.
  • Date filtering — select records on or before a deadline with { dueDate: { $lte: date } }.
  • Threshold analysis — extract data points at or below performance or quality thresholds.
  • Inclusive ranges — combine with $gte for bounded intervals that include both endpoints.

🧠 How $lte Works

1

MongoDB reads the operands

In $match, it checks a field against a threshold. In expressions, it evaluates two operands like "$age" and 20.

Input
2

$lte compares values

MongoDB checks whether the first value is less 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 below a threshold, including boundary values.

Conclusion

The $lte operator is essential for inclusive upper-bound filtering in MongoDB. It powers cap-based queries in $match and find(), boolean flags in $project, and pairs with $gte for full inclusive ranges.

Remember the key distinction: $lte includes values equal to the threshold, while $lt does not. Choose the operator that matches your business rule exactly.

💡 Best Practices

✅ Do

  • Use $lte when boundary values should be included
  • Pair with $gte for inclusive min–max ranges
  • Use query form in $match and find()
  • Use expression form in $project and $cond
  • Index fields used in $lte filters for better performance

❌ Don’t

  • Use $lt when equals should match (use $lte)
  • Use expression form inside $match without $expr
  • Compare different BSON types and expect reliable results
  • Confuse $lte with $lt or $gte
  • Forget that $lte works with dates for “on or before” filters

Key Takeaways

Knowledge Unlocked

Five things to remember about $lte

Use these points when writing less-than-or-equal comparisons in MongoDB.

5
Core concepts
📝 02

Two Forms

Query filter vs expression.

Syntax
🛠 03

vs $lt

Equals included.

Compare
🔍 04

Range Pairs

With $gte.

Pattern
📅 05

Date Caps

On or before.

Use case

❓ Frequently Asked Questions

$lte checks whether one value is less than or equal to another. In query filters it matches documents where a field is at or below a threshold. In aggregation expressions it returns true or false when comparing two expressions.
Query form: { field: { $lte: value } }. Aggregation expression form: { $lte: [ <expression1>, <expression2> ] }. There is no shorthand — you must use the explicit $lte operator.
$lte includes values equal to the threshold. $lt is strictly less than and excludes equals. For example, { age: { $lte: 20 } } matches 20, but { age: { $lt: 20 } } does not.
In $match, $lte filters documents at or below the threshold. In $project or $addFields, $lte compares two expressions and adds a boolean field (true/false) to each document.
Yes. $lte 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 $ltrim for trimming leading whitespace, or review $lt for strict less-than comparisons.

Next: $ltrim →

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