The Wayback Machine - https://web.archive.org/web/20260305042917/https://www.geeksforgeeks.org/mongodb/mongodb-less-than-operator-lt/

MongoDB $lt Operator

Last Updated : 9 Feb, 2026

The $lt operator in MongoDB filters documents where a field’s value is strictly less than a specified value and is commonly used in find(), update(), and aggregation pipelines.

  • Filters documents with values less than a given threshold.
  • Works with numbers, dates, and arrays.
  • Useful for range-based queries and filtering before sorting.
  • Supports indexing to improve query performance.
  • Compares values of compatible data types only (e.g., number with number).

Syntax

{field: {$lt: value}}
  • field: The field name to compare.
  • $lt: Specifies the less than condition.
  • value: The threshold value to compare against.

Important Points About $lt in MongoDB

Here are features discussed:

  • Filters documents where a field value is strictly less than a given value.
  • Works with numbers, dates, and arrays.
  • Usable in find(), updateMany(), and aggregation stages like $match.
  • Performs faster when relevant fields are indexed.
  • Compares compatible data types to ensure accurate results.

Examples of MongoDB $lt Operator

For these examples, we assume the following setup

  • Database: GeeksforGeeks
  • Collection: employee
  • Document: Four documents that contain the details of the employees in the form of field-value pairs.
Screenshot-2026-02-09-113337

Example 1: Find Employees with Salary Less Than 35,000

Retrieving those documents where the value of the salary field is less than 35000.

Query:

db.employee.find({salary: {$lt:55000}})

Output:

Screenshot-2026-02-09-113508

Example 2: Find Employees Younger Than 24 Years

Retrieving only those documents where the age of the employee is less than 24.

Query:

db.employee.find({"personalDetails.age": { $lt: 24 }})

Output:

Screenshot-2026-02-09-113955


Example 3: Comparing Arrays with $lt Operator

Retrieving only those documents where the points array is less than the specified array. MongoDB compares arrays lexicographically (similar to string sorting).

Query:

db.employee.find({ points: { $lt: [50, 70, 90] } })

Output:

Screenshot-2026-02-09-114120

Example 4: Update Salaries for Employees with Less Than 2 Years of Experience

Updating the salary of those employees whose experience year is less than 2 years.

Query:

db.employee.updateMany({ experienceYear: { $lt: 2 } }, { $set: { salary: 40000 } })

Output:

Screenshot-2026-02-09-114502

Performance Optimization Tips for Using $lt

To improve query performance when using the $lt operator, follow these best practices:

1. Use Indexing for Faster Queries

Create indexes on frequently filtered fields so $lt queries run efficiently.

db.employee.createIndex({ salary: 1 })

2. Avoid Large Collection Scans

Without indexes, $lt queries may scan the entire collection, slowing performance.

3. Use Projection to Limit Retrieved Fields

Return only required fields to reduce data transfer and processing time.

db.employee.find({ salary: { $lt: 35000 } }, { name: 1, salary: 1 })

4. Ensure Proper Data Type Comparisons

Compare compatible data types (e.g., numbers with numbers) to avoid incorrect results and slow queries.

Comment

Explore