Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

MongoDB – Greater than Operator $gt

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

MongoDB provides different types of comparison operators and greater than operator($gt) is one of them. This operator is used to select those documents where the value of the field is greater than(>) the given value. You can use this operator in methods (like, find, update, etc.) according to your requirements.

Syntax:

{field: {$gt: value}}

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.

 
Example #1:
In this example, we are selecting those documents where the value of the salary field is greater than 35000.

 
Example #2:
In this example, we are selecting only those documents where the age of the employee is greater than 23. Or in other words, in this example, we are specifying conditions on the field in the embedded document using dot notation.

 
Example #3:
In this example, we are selecting only those documents where the points array is greater than the specified array.

 
Example #4:
In this example, we are updating the salary of those employees whose experience year is greater than 2 years. Or in other words, set the value of the salary field to 49000 of those documents whose experienceYear field value is greater than 2.

My Personal Notes arrow_drop_up
Last Updated : 27 Mar, 2020
Like Article
Save Article
Similar Reads