The Wayback Machine - https://web.archive.org/web/20250207102906/https://www.geeksforgeeks.org/mongodb-less-than-operator-lt/
Open In App

MongoDB – $lt Operator

Last Updated : 23 Apr, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

MongoDB $lt operator or less than operator is one of the comparison operators. The $lt operator selects the documents with a value less than (<) the given value.

You can use this operator in methods like, find(), update(), etc. as per your requirements.

Syntax

{field: {$lt: value}}

MongoDB $lt Operator Example

In the following examples, we are working with:

Database: GeeksforGeeks

Collection: employee

Document: four documents that contain the details of the employees in the form of field-value pairs.

demo database and collection

Example 1

In this example, we are selecting those documents where the value of the salary field is less than 35000.

Query:

find({salary: {lt:35000}}).pretty()

Output:

mongodb $lt operator example 1

Example 2:

In this example, we are selecting only those documents where the age of the employee is less than 24.

mongodb $lt operator example 2

Example 3:

In this example, we are selecting only those documents where the points array is less than the specified array.

mongodb $lt operator example 3

Example 4:

In this example, we are updating the salary of those employees whose experience year is less than 2 years.

mongodb $lt operator example 4

Key Takeaways About $lt Operator

  • MongoDB $lt operator also known as less than operator is a comparison operator.
  • It selects the documents where value of specific field is less than the given value.
  • It can only compare similar data types. for example, string data type can not be compared with integer.
  • It is useful for filtering wide range of documents.

Next Article
Article Tags :

Similar Reads

three90RightbarBannerImg