MongoDB $lt Operator

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

What You’ll Learn

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.

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

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

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

⚡ Quick Reference

QuestionAnswer
Operator typeComparison operator (query + expression)
Query syntax{ field: { $lt: value } }
Expression syntax{ $lt: [ expr1, expr2 ] }
Includes equals?No — use $lte for ≤
Expression outputtrue or false
Common stages$match, $project, $cond
$match filter
{
  age: { $lt: 21 }
}

Under 21 years old

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

Returns true/false

Field vs field
{
  $lt: [
    "$spent",
    "$budget"
  ]
}

Under budget check

find()
db.products.find({
  price: { $lt: 50 }
})

Works in find too

Examples Gallery

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

📚 Filter by Age

Use a students collection and find everyone younger than 21 with $match.

Sample Input Documents

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

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

Example 1 — $lt in a $match Stage

Find students younger than 21:

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

How It Works

  • Alice (20) and Charlie (18) are less than 21, so they pass the filter.
  • Bob (25) is excluded because 25 is not less than 21.
  • A student aged exactly 21 would also be excluded — use $lte to include age 21.

📈 Practical Patterns

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

Example 2 — $lt in a find() Query

The same query form works outside aggregation pipelines:

mongosh
db.products.find({
  price: { $lt: 50 }
})

How It Works

$lt in find() uses the same query form as $match. It is one of the most common ways to filter numeric and date fields in MongoDB.

Example 3 — Add a Boolean Field with $project

Flag products priced below 100 on every document:

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

How It Works

The expression form does not filter documents. It adds true or false to every document based on whether price is below 100.

Example 4 — $lt Inside $cond

Label students as “minor” or “adult” based on age:

mongosh
db.students.aggregate([
  {
    $project: {
      name: 1,
      age: 1,
      category: {
        $cond: [
          { $lt: [ "$age", 18 ] },
          "minor",
          "adult"
        ]
      }
    }
  }
])

How It Works

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.

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

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.

💡 Best Practices

✅ Do

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

Key Takeaways

Knowledge Unlocked

Five things to remember about $lt

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

5
Core concepts
📝 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.

Continue the Operator Series

Move on to $lte for less-than-or-equal comparisons, or review $gt for greater-than checks.

Next: $lte →

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