MongoDB $lt Operator

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

What Is $lt?

$lt means less than. Use it to filter documents where a field is below a value, or in aggregation to return true / false from a comparison. Equality does not match—use $lte for that.

Remember
$lt = less than (strict)

Query filter:
  { score: { $lt: 80 } }

Aggregation expression:
  { $lt: [ "$score", 80 ] }  → true / false

72 < 80 → true (kept / true)
80 < 80 → false (excluded / false)
85 < 80 → false

sibling: $lte includes equals
UsePrefer
Strictly less than$lt
Less than or equal$lte
Greater than$gt

How to Use $lt in MongoDB

Pick filter mode (keep documents) or expression mode (boolean field).

  1. For filtering: use find() or $match with { field: { $lt: value } }.
  2. For a boolean: use $addFields / $project with { $lt: [ expr1, expr2 ] }.
  3. To compare two fields in a filter, wrap with $expr.
  4. Use $lte when the boundary value should also match.
PieceRequired?Role
Query form—{ field: { $lt: value } } filters docs
Expression form—{ $lt: [ a, b ] } → boolean
OperandsYesSame BSON type when possible

Pseudocode

Pseudocode
// Filter mode
for each document:
    if field < threshold:
        keep document
    else:
        drop document

// Expression mode
for each document:
    result = (expr1 < expr2)   // true or false
    emit { ..., field: result }

Cheat Sheet

Keep these facts handy while writing less-than checks.

TopicDetail
MeaningLess than (excludes equals)
Query syntax{ field: { $lt: value } }
Agg syntax{ $lt: [ <a>, <b> ] }
vs $lte$lte includes equality
Two fields in findUse $expr + $lt
TypesNumbers, dates, strings (BSON order)
Sample checkscore: { $lt: 80 } keeps 72, drops 80

Live Preview

Watch $lt test whether a score is less than 80.

Simulates { score: { $lt: 80 } } / { $lt: [ score, 80 ] }.

Result
score = 72
threshold = 80
$lt → true (kept / below)

Worked Walkthrough — Scores Below 80

Keep students whose score is less than 80.

Calculation
Documents:
  { name: "Asha", score: 85 }
  { name: "Ben",  score: 72 }

Test: score < 80

Asha: 85 < 80 → false → drop
Ben:  72 < 80 → true  → keep

Result: only Ben

MongoDB Examples

We use two students. First filter with a query, then add a boolean field in aggregation. Run these in mongosh after inserting the sample data once.

Example 1 — Sample Data

Imagine two students: Asha scored 85 and Ben scored 72. We save both in a collection named students.

mongosh
db.students.insertMany([
  { _id: 1, name: "Asha", score: 85 },
  { _id: 2, name: "Ben", score: 72 }
]);

How the Data Is Stored in MongoDB

After the insert, MongoDB keeps two documents in students. Run find() to see them:

mongosh
db.students.find()

Read those documents like this:

Field in MongoDBAshaBen
_id12
name"Asha""Ben"
score8572
Picture
Threshold line at 80:

  Ben 72 ........ 80 ........ Asha 85
                 |
            score < 80 ?

  Ben  → yes
  Asha → no

How It Works

  1. Insert once. insertMany adds two student documents to students.
  2. Scores are numbers. Ready for numeric comparison with $lt.
  3. find() shows both rows. The next example keeps only the ones below 80.

Example 2 — Filter with $lt

Goal: return only students whose score is less than 80.

mongosh
db.students.find({
  score: { $lt: 80 }
});

How It Works

  1. Apply a filter. { score: { $lt: 80 } } means “score must be < 80”.
  2. Test each document. Ben 72 passes; Asha 85 fails.
  3. Only matches remain. The result set is just Ben’s document.

Example 3 — Boolean Expression

Same students, but keep every document and add a below boolean with the aggregation form of $lt.

mongosh
db.students.aggregate([
  {
    $addFields: {
      below: {
        $lt: ["$score", 80]
      }
    }
  }
]);

How It Works

  1. Same stored documents. Still using Asha and Ben from Example 1.
  2. Compare as an expression. { $lt: ["$score", 80] } returns a boolean per document.
  3. Nothing is dropped. Both rows stay; only the new below flag differs.

Edge Cases & Pitfalls

Check these before using $lt in production queries.

equals

Equals do not match

{ score: { $lt: 80 } } excludes 80. Use $lte when the boundary should pass.

types

Type mismatches surprise

Comparing a number to a string uses BSON type order, not numeric math. Keep types consistent.

fields

Two fields need $expr in find

To filter with spent < budget, use $expr: { $expr: { $lt: ["$spent", "$budget"] } }.

index

Range filters love indexes

An index on the compared field helps $lt / $lte range scans stay fast on large collections.

Performance Notes

ApproachCostBest for
Indexed $lt filterRange scanLarge collections with a field index
Unindexed $ltCollection scanSmall data or rare queries
Agg boolean $ltPer-document compareFlags without dropping rows

Put selective $lt filters early in $match so later stages see fewer documents.

Key Takeaways

  • Role: strict less-than comparison.
  • Filter: { field: { $lt: value } }.
  • Expression: { $lt: [ a, b ] } → boolean.
  • Equals: use $lte when the boundary should match.

One line: $lt answers “is this value strictly less than that?”—as a filter or as a boolean.

Frequently Asked Questions

$lt means less than. In a query filter it keeps documents where a field is below a value. In aggregation expressions it compares two expressions and returns true or false. Equality does not match.
Query form: { field: { $lt: value } }. Aggregation form: { $lt: [ <expression1>, <expression2> ] }. There is no shorthand for less-than.
$lt is strict less than (excludes equality). $lte is less than or equal (includes equality). Score 80 matches { score: { $lte: 80 } } but not { score: { $lt: 80 } }.
Yes in aggregation: { $lt: [ "$spent", "$budget" ] }. In a find filter, compare two fields with $expr and $lt.
Yes. Numbers compare numerically, dates chronologically, and strings lexicographically. Keep operand types consistent for predictable results.
In find() / $match filters to select documents, and in expression stages like $project and $addFields to create boolean fields.

Next: $lte

Include the boundary value with less-than-or-equal comparisons.

$lte tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

9 people found this page helpful