_4_ operator MongoDB study notes
Others
2019-10-14 00:28:20
views: null
Operators
Comparison operators
1 |
$eq |
equal |
2 |
$lt |
Less than |
3 |
$ lte |
Less than or equal |
4 |
$gt |
more than the |
5 |
$gte |
greater or equal to |
6 |
$ does |
not equal to |
7 |
$in |
contain |
8 |
$ s |
Does not contain |
- eg
db.class.find({age:{$eq:22}},{_id:0,name:1})
- eg
db.class.find({age:{$lt:22}},{_id:0,name:1})
- eg
db.class.find({age:{$in:[22,23]]}},{_id:0,name:1})
Logical Operators
1 |
$and |
Logic and |
2 |
$or |
Logical or |
3 |
$not |
Logical NOT |
4 |
$nor |
Neither nor |
- eg
db.class.find({$or:[{age:{$lt:22}},{sex:'w'}]},{_id:0,name:1})
Find Array
1 |
$all |
Find the array contains a number of documents |
2 |
$size |
Find the number of items in the array to the specified number of documents |
3 |
$slice |
Several display array ago |
- eg display first
hobby db.class.find({},{hobby:{$slice:1}})
- After skipping the first two eg, display
hobby db.class.find({},{hobby:{$slice:[1,2]}})
other
1 |
$exist |
Determining whether there is a field |
2 |
$mod |
Remainder |
3 |
$type |
Find the value of specified types of documents |
- eg find documents exist sex domain
db.class.find({sex:{$exists:true},{_id:0}})
- eg Find age divisible by 3 documents
db.class.find({age:{$mod:[3,0]},{_id:0}})
Query commonly used functions
1 |
distinct()) |
The value of a field of view covered by the scope of the collection |
2 |
pretty() |
Formatted output |
3 |
limit(n) |
Query results are displayed first n documents |
4 |
skip(n) |
Skip the first n lines of the document display |
5 |
count() |
count |
6 |
sort() |
Sort by the specified field |
5 |
count() |
count |
Origin www.cnblogs.com/donyblog/p/11668165.html