MongoDB Update Operators
Description
A conditional operator compares two expressions and fetched documents from mongodb collection. In this page we are going to discuss about the conditional operators and usage of conditional operators.
In MongoDB the conditional operators are :
(>) greater than - $gt
(<) less than - $lt
(>=) greater than equal to - $gte
(<= ) less than equal to - $lte
Our database name is 'myinfo' and our collection name is 'testtable'. Here, is the collection bellow.
Sample collection "testtable"
![mongodb testtable in dot notation sample collection](https://www.w3resource.com/w3r_images/mongodb-testtable-dot-notation-sample.gif)
MongoDB (>) greater than operator - $gt
If we want to fetch documents from the collection "testtable" which contains the value of "age " is more than 22, the following mongodb command can be used :
Sql equivalent command is
Output of the command
![MongoDB greater than operator](https://www.w3resource.com/w3r_images/mongodb-greater-than-operator.gif)
MongoDB (>=) greater than equal to operator - $gte
If we want to fetch documents from the collection "testtable" which contains the value of "age " is more than or equla to 22, the following mongodb command can be used :
Sql equivalent command is
Output of the command
![MongoDB greater than equal to](https://www.w3resource.com/w3r_images/mongodb-greater-than-equal-to-operator.gif)
MongoDB (<) less than operator - $lt
If we want to fetch documents from the collection "testtable" which contains the value of "age " is less than 19, the following mongodb command can be used :
Sql equivalent command is
Output of the command
![MongoDB less than operator](https://www.w3resource.com/w3r_images/mongodb-less-than-operator.gif)
MongoDB (<=) less than equal to operator - $lte
If we want to fetch documents from the collection "testtable" which contains the value of "age " is less than or equal to 19, the following mongodb command can be used :
Sql equivalent command is
Output of the command
![MongoDB less than equal to operator](https://www.w3resource.com/w3r_images/mongodb-less-than-equal-to-operator.gif)
MongoDB query using (<) and (>) operator - $lt and $gt
If we want to fetch documents from the collection "testtable" which contains the value of "age " is greater than 17 and less than 24, the following mongodb command can be used :
Sql equivalent command is
Output of the command
![MongoDB greater than and less than operator](https://www.w3resource.com/w3r_images/mongodb-less-than-greater-than-operator.gif)
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics