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.
Fundamentals
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: $lteincludes values equal to the threshold. { age: { $lte: 20 } } matches age 20; { age: { $lt: 20 } } does not.
Foundation
📝 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
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.
Applications
🚀 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.
Wrap Up
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.
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
Summary
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
🔢01
Less or Equal
Includes boundary.
Purpose
📝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.