当前位置:网站首页>Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)
Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)
2022-07-02 11:09:00 【JAVA·D·WangJing】
One 、 Add test data
### Insert test data
db.wangjing_test.insert({"name":"wangjing","sex":" male ","age":27,"height":175,"weight":100});
db.wangjing_test.insert({"name":"wangjing1","sex":" male ","age":37,"height":185,"weight":110});
db.wangjing_test.insert({"name":"wangjing2","sex":" male ","age":47,"height":195,"weight":120});
db.wangjing_test.insert({"name":"wangjing3","sex":" male ","age":57,"height":205,"weight":130});
Two 、 Conditional operators
#### The conditional operator is used to compare two expressions and mongoDB Get data in collection .
### MongoDB The conditional operators in are :
# (>) Greater than - $gt
# (<) Less than - $lt
# (>=) Greater than or equal to - $gte
# (<= ) Less than or equal to - $lte
### (>=) Greater than or equal to operator - $gte
# Inquire about age Greater than or equal to 37 year
db.wangjing_test.find({age : {$gte : 37}})
### (>) Greater than operator - $gt
# Query age is greater than 37 year
db.wangjing_test.find({age : {$gt : 37}})
### MongoDB (<=) Less than or equal to operator - $lte
# Query age is less than or equal to 37 year
db.wangjing_test.find({age : {$lte : 37}})
### (<) Less than operator - $lt
# The query age is less than 37 year
db.wangjing_test.find({age : {$lt : 37}})
### MongoDB Use (<) and (>) Inquire about - $lt and $gt
# The query age is less than 50 year , Greater than 30 year
db.wangjing_test.find({age : {$lt : 50, $gt : 30}})
3、 ... and 、$type The operator
#### $type Operators are based on BSON Type to retrieve the matching data types in the collection , And return the result .
### Types that can be used in :
# type Numbers remarks
# Double 1
# String 2
# Object 3
# Array 4
# Binary data 5
# Undefined 6 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
# Inquire about name Data as string
db.wangjing_test.find({"name" : {$type : 2}})
Four 、limit() Method
#### limit Method to specify the number of queries ,limit() Method accepts a numeric parameter .
# Query two pieces of data
db.wangjing_test.find().limit(2)
5、 ... and 、skip() Method
#### skip() Method to skip a specified amount of data ,skip Method also accepts a numeric parameter as the number of records to skip .
# Query the second data
db.wangjing_test.find().limit(1).skip(1)
6、 ... and 、sort() Method
#### sort() Method to sort the data ,sort() Method can be used to specify the sorting field by parameter , And use 1 and -1 To specify how to sort , among 1 Arrange... In ascending order , and -1 It's for descending order .
# Query according to age classification
db.wangjing_test.find().sort({age:-1})
notes : The above contents are only for reference and exchange , Do not use for commercial purposes , If there is infringement, please contact me to delete !
边栏推荐
- Set the playback speed during the playback of UOB equipment
- 二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)
- Openmldb meetup No.4 meeting minutes
- AppGallery Connect场景化开发实战—图片存储分享
- 二叉树专题--AcWing 3540. 二叉搜索树建树(实用板子 构建二叉搜索树 并输出前、中、后序遍历)
- 【AppLinking实战案例】通过AppLinking分享应用内图片
- Matlab processing of distance measurement of experimental electron microscope
- 2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
- TIPC 寻址2
- From Read and save in bag file Jpg pictures and PCD point cloud
猜你喜欢
![二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)](/img/c2/bb85b681af0f78b380b1d179c7ea49.png)
二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)

Special topic of binary tree -- acwing 1497 Traversal of the tree (use post and mid order traversal to build a binary tree)

【深入浅出玩转FPGA学习2----设计技巧(基本语法)】

Special topic of binary tree -- acwing 1589 Building binary search tree

Open the encrypted SQLite method with sqlcipher

How to use ide to automatically sign and debug Hongmeng application
![[applinking practical case] share in app pictures through applinking](/img/12/5616f1fa55387b81e25e55a98022b9.png)
[applinking practical case] share in app pictures through applinking

HDU1234 开门人和关门人(水题)

Nodejs+express+mysql simple blog building

华为快应用中如何实现同时传递事件对象和自定义参数
随机推荐
Special topic of binary tree -- acwing 18 Rebuild the binary tree (construct the binary tree by traversing the front and middle order)
[AGC] how to solve the problem that the local display of event analysis data is inconsistent with that in AGC panel?
Open the encrypted SQLite method with sqlcipher
flink二开,实现了个 batch lookup join(附源码)
Special topic of binary tree -- acwing 3384 Binary tree traversal (known preorder traversal, while building a tree, while outputting middle order traversal)
Leetcode 182 Find duplicate email (2022.07.01)
TIPC Service and Topology Tracking4
二叉树专题--【深基16.例7】普通二叉树(简化版)(multiset 求前驱 后继 哨兵法)
PCL eigen introduction and simple use
P1055 [NOIP2008 普及组] ISBN 号码
二.Stm32f407芯片GPIO编程,寄存器操作,库函数操作和位段操作
[in simple terms, play with FPGA learning 3 ----- basic grammar]
MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
[AI application] Hikvision ivms-4200 software installation
QT learning diary 8 - resource file addition
How to implement tabbar title bar with list component
Regular and common formulas
Flink two Open, implement Batch Lookup join (attached source)
二叉树专题--P1030 [NOIP2001 普及组] 求先序排列
[play with FPGA learning 2 in simple terms ----- design skills (basic grammar)]