The $lt operator checks whether one value is less than another. Use it in $match to filter documents below a threshold, or in expression stages like $project and $cond to compare fields and get a true/false result.
01
Less Than
Left value < right value.
02
Two Syntax Forms
Query filter vs expression.
03
$match Stage
Filter below threshold.
04
Boolean Output
true or false in $project.
05
Use Cases
Ages, prices, dates.
06
vs $lte
Strict vs inclusive.
Fundamentals
Definition and Usage
In MongoDB, the $lt operator tests whether one value is strictly less than another. In a $match stage, { age: { $lt: 21 } } filters documents where age is less than 21. In an aggregation expression, { $lt: [ "$price", 100 ] } returns true or false for each document. It is one of the core comparison operators alongside $lte, $gt, and $gte.
💡
Beginner Tip
Unlike $eq, there is no shorthand for $lt. You must always write { age: { $lt: 21 } } explicitly. Values equal to the threshold are not included — use $lte for “less than or equal.”
Foundation
📝 Syntax
$lt has two forms depending on where you use it:
Query form (in $match or find filters)
mongosh
{ field: { $lt: <value> } }
Aggregation expression form (in $project, $cond, etc.)
mongosh
{ $lt: [ <expression1>, <expression2> ] }
Syntax Rules
Query form — filters documents where the field is less than the given value.
Expression form — compares two expressions and returns true or false.
Strictly less than — equal values return false (use $lte to include equals).
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 $lt returns true (age < 18), $cond outputs "minor". Otherwise it outputs "adult". Charlie (18) gets "adult" because 18 is not strictly less than 18.
Bonus — Range Query with $gt and $lt
Combine comparison operators to filter a range (exclusive on both ends):
mongosh
db.students.aggregate([
{
$match: {
age: { $gt: 18, $lt: 25 }
}
}
])
// Matches students older than 18 AND younger than 25
// Alice (20) → included
// Bob (25) → excluded (25 is not < 25)
// Charlie (18) → excluded (18 is not > 18)
How It Works
Multiple comparison operators on the same field are combined with implicit $and. Use $gte and $lte when you want to include the boundary values.
Applications
🚀 Use Cases
Age and eligibility filtering — find users below a minimum age or senior discount threshold.
Price caps — retrieve products or orders under a budget limit.
Date filtering — select records created before a specific date using { createdAt: { $lt: date } }.
Conditional logic — use as the if condition inside $cond for tiered labels and alerts.
🧠 How $lt Works
1
MongoDB reads the operands
In $match, it checks a field against a threshold. In expressions, it evaluates two operands like "$age" and 21.
Input
2
$lt compares values
MongoDB checks whether the first value is strictly less than 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 below a threshold or boolean fields ready for conditional logic.
Wrap Up
Conclusion
The $lt operator is a core comparison tool in MongoDB. It powers threshold filtering in $match and find(), boolean field creation in $project, and conditional branching in $cond — making it essential for range-based queries.
For beginners, remember two forms: query form { field: { $lt: value } } filters documents, and expression form { $lt: [ expr1, expr2 ] } returns true or false. Use $lte when you need to include values equal to the threshold.
Use query form in $match and find() for threshold filtering
Use expression form in $project and $cond
Use $lte when equal values should be included
Combine with $gt for range queries
Index fields used in $lt filters for better performance
❌ Don’t
Expect values equal to the threshold to match (use $lte)
Use expression form inside $match without $expr
Compare different BSON types and expect reliable results
Confuse $lt with $lte or $gt
Use $lt when you need exact equality (use $eq)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about $lt
Use these points when writing less-than comparisons in MongoDB.
5
Core concepts
🔢01
Less Than
Strictly below threshold.
Purpose
📝02
Two Forms
Query filter vs expression.
Syntax
🛠03
$match Filter
Below-threshold docs.
Usage
🔍04
$cond Ready
Boolean for if-then-else.
Use case
⚠05
Not $lte
Equals excluded.
Edge case
❓ Frequently Asked Questions
$lt checks whether one value is less than another. In query filters it matches documents where a field is below a threshold. In aggregation expressions it returns true or false when comparing two expressions.
Query form: { field: { $lt: value } }. Aggregation expression form: { $lt: [ <expression1>, <expression2> ] }. Unlike $eq, there is no shorthand — you must use the explicit $lt operator.
In $match, $lt filters documents and keeps only those where the field is below the threshold. In $project or $addFields, $lt compares two expressions and adds a boolean field (true/false) to each document.
$lt is strictly less than — equal values do not match. $lte includes values equal to the threshold. For example, age 21 matches { age: { $lte: 21 } } but not { age: { $lt: 21 } }.
Yes. $lt uses BSON comparison order. Dates compare chronologically, numbers numerically, and strings lexicographically. Ensure both operands are the same type for predictable results.