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 (>) 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 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 (<) 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 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 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
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/mongodb/mongodb-query-modifiers.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics