Matching values using $gt operator
In this example, we are selecting those documents where the value of the salary field is greater than 1000.
Query:
db.contributor.find({salary: {$gt: 1000}}).pretty()
Output:
Using $gte
operator
In this example, we are selecting those documents where the value of the joiningYear field is greater than equals to 2017.
Query:
db.contributor.find({joiningYear: {$gte: 2017}})
Output:
MongoDB – Comparison Query Operators
Comparison Query Operators in MongoDB are used to filter documents based on some specific criteria within their fields.
MongoDB uses various comparison query operators to compare the values of the documents. The following table contains the comparison query operators:
Operators | Description |
---|---|
$eq | Matches the values of the fields that are equal to a specified value. |
$ne | Matches all values of the field that are not equal to a specified value. |
$gt | Matches values of the fields that are greater than a specified value. |
$gte | Matches values of the fields that are greater than equal to the specified value. |
$lt | Matches values of the fields that are less than a specified value |
$lte | Matches values of the fields that are less than equal to the specified value |
$in | Matches any of the values specified in an array. |
$nin | Matches none of the values specified in an array. |
Contact Us