1. Some explanations
- Less than: than. Less LT
- Greater than: than. Multi-GT
- equals: Equal E
the conditional operators in MongoDB are:
- (>) Greater than-$GT
- (<) less than-$lt
- (>=) greater than or equal to-$gte
- (<=) less than or equal to-$lte
MongoDB (>) greater than Operator-$GT
If you want to get more than 100 of the "likes" data in the "Col" collection, you can use the following command:
Db.col.find ({"likes": {$gt: 100}})
Similar to the SQL statement:
Select * from Col where likes > 100; MongoDB (>=) greater than equals operator-$gte
If you want to get data with "likes" greater than or equal to 100 in the "Col" collection, you can use the following command:
Db.col.find ({likes: {$gte: 100}})
Similar to the SQL statement:
Select * from Col where likes >=100; MongoDB (<) less than operator-$LT
If you want to get data that is less than 150 "likes" in the "Col" collection, you can use the following command:
Db.col.find ({likes: {$lt: 150}})
Similar to the SQL statement:
Select * from Col where likes < 150; MongoDB (<=) less than operator-$lte
If you want to obtain data that is less than or equal to 150 of "likes" in the "Col" collection, you can use the following command:
Db.col.find ({likes: {$lte: 150}})
Similar to the SQL statement:
Select * from Col where likes <= 150; MongoDB Use (<) and (>) queries-$lt and $GT
If you want to get "likes" in the "Col" collection greater than 100, less than 200 of the data, you can use the following command:
Db.col.find ({likes: {$lt: $, $GT: 100}})
Similar to the SQL statement:
Select * from Col where likes>100 and likes<200;
MongoDB $type operator
The types that can be used in MongoDB are shown in the following table:
type |
Digital |
Notes |
Double |
1 |
|
String |
2 |
|
Object |
3 |
|
Array |
4 |
|
Binary data |
5 |
|
Undefined |
6 |
is obsolete. |
Object ID |
7 |
|
Boolean |
8 |
|
Date |
9 |
|
Null |
10 |
|
Regular Expression |
11 |
|
Javascript |
13 |
|
Symbol |
14 |
|
JavaScript (with scope) |
15 |
|
32-bit integer |
16 |
|
Timestamp |
17 |
|
64-bit integer |
18 |
|
Min Key |
255 |
Query with -1. |
Max Key |
127 |
|
If you want to get the data in the "Col" collection with the title String, you can use the following command: Db.col.find ({"title": {$type: 2}}) From:http://www.runoob.com/mongodb/mong Odb-operators.html
mongodb-Base-Conditional operator