One, comparison operators
| operator |
operators that correspond to MySQL |
| $gt |
> |
| $gte |
>= |
| $in |
In |
| $lt |
< |
| $lte |
<= |
| $ne |
!= |
| $nin |
Not in |
| $all |
None of the corresponding items, the index group all cell matching have, use the same $in, $nin |
Syntax format:
{column name: {$gt: Value}}
{column name: {$ne: Value}}
{column name: {$in: [Value1,value2,value3 ...]}}
Note:
two, logical operators
| operator |
operators that correspond to MySQL |
| $or |
Or |
| $and |
and |
| $not |
Not |
| $nor |
No corresponding item, meaning "All listed conditions are not valid, true" |
Syntax format:
{$and: [{columns: {$gte: value1}},{columns: {$gle: Value2}}]}
{$nor: [{columns: value1},{columns: value2},{columns: Value3} ...]}
three, element operator
| name |
Description |
| $exists |
True if a column exists |
| $mod |
Satisfies a certain remainder condition to be true |
| $type |
Data is true for a type |
Whether a column exists {column: {$exists: 1}} #1表示存在
5 times times columns: {column: {$mod: [5,0]}} #[5,0] represents a remainder of 5, with 0
type {column: {$type: 2}}
type values from 1 to 19, and-1 and 127 corresponding data types check the official documentation:
https://docs.mongodb.com/manual/reference/operator/query/type/index.html
Four, JS operator (1)
| name |
Description |
| $where |
The JS expression is true is true |
| $regex |
Regular expression matches are true |
$where and $regex is to convert all the Bson first to JSON object, and then for the JS engine query, memory consumption is more
suitable for a small number of data queries, generally do not recommend the
syntax format:
{$where: ' this. Column > Value1 && this. Column < value2 ... '}
{column: {$regex:/pattern/<options>}}
for example: {
name: {$regex: /acme.*corp/i, $nin: [' Acmeblahcorp ']}}
{name: {$regex:/acme.*corp/, $options: ' I ', $nin: [' Acmeblahcorp ']}
{name: {$regex: ' Acme.*corp ', $options: ' I ', $nin: [' Acmeblahcorp ']}}
Five, JS operator (2)
| name |
Description |
| $inc |
Growth |
| $rename |
renaming columns |
| $setOnInsert |
Set the value of a field when Upsert |
| $set |
Set a new value for a field |
| $unset |
Deletes the specified column |