当前位置:网站首页>Mongodb sort function
Mongodb sort function
2022-06-29 06:10:00 【icestone_ kai】
Sorting function
cursor.sort({
field: ordering, ...}): Sort according to the specified rules
ordering by 1 Indicates ascending sort
ordering by -1 Represents a descending sort
Example
// Be careful : By default find Method only returns 100 A document
db.person.find()
db.person.insert({
name:'itzb', age:15})
db.person.find().limit(101)
db.person.find().sort({
age:1})
db.person.find().sort({
age:-1})
Be careful
3.1find Method will only fetch by default 100 A document
3.2sort The function always executes before the paging function
db.person.find().skip(5).limit(5)
db.person.find().skip(5).limit(5).sort({
age:-1})
code:
show databases;
use usser;
show collections;
db.person.find()
db.person.insertOne({
name:'itzb',age:12})
// Be careful : By default find Method only returns 100 A document
// Returns the specified quantity :
db.person.find().limit(500)
// Specify the ascending order of age
db.person.find().sort({
age:1}).limit(200)
// Specify the descending order of age
db.person.find().sort({
age:-1}).limit(200)
Be careful :sort Function if and limit,skip When used together , No matter what sort Before or after , Will execute first sort function
边栏推荐
- Analysis report on the investment market of the development planning prospect of the recommended rare earth industry research industry in 2022 (the attachment is a link to the online disk, and the rep
- 2022 recommended high-speed rail industry research report investment strategy industry development prospect market analysis (the attachment is a link to the online disk, and the report is continuously
- Est - ce que l'ouverture d'un compte de titres est sécurisée? Y a - t - il un danger?
- Boost the digital economy and face the future office | the launch of the new version of spreadjsv15.0 is about to begin
- QT writing map comprehensive application 58 compatible with multi browser kernel
- Why is there a packaging type?
- Awk of shell script
- DataX connection MySQL cannot find driver
- Week 12 - task 2- shoulder to shoulder cadres
- It turns out that the joys and sorrows of programmers are not interlinked
猜你喜欢

How to insert pseudo code into word documents simply and quickly?

2022 recommended trend toy blind box industry research report industry development prospect market analysis white paper (the attachment is a link to the network disk, and the report is continuously up

Difference between URI and URL

Jenkins operation Chapter 6 mail server sending build results

The generation of leetcode simple questions each character is an odd number of strings

Programming specification and variables of shell script

QT writing map comprehensive application 58 compatible with multi browser kernel

Leetcode simple problem building arrays with stack operation

Analysis report on the investment market of the development planning prospect of the recommended NFT industry research industry in 2022 (the attachment is a link to the online disk, and the report is

Hyperledger Fabric 2. X custom smart contract
随机推荐
Maximum ascending subarray sum of leetcode simple problem
Rich material libraries make modeling easy and efficient for developers
QT precautions and RCC download address
The win11 file resource manager has an explicit Caton, and Microsoft promises to improve the performance in 2022
Purple red solid meso tetra (o-alkoxyphenyl) porphyrin cobalt (meso-t (2-rop) PCO) / tetra (n, n-diphenyl-p-amino) phenyl porphyrin (tdpatph2)
Can use the mouse, will reinstall the computer system tutorial sharing
Case of single file component files
In 2022, I haven't found a job yet. I have been unemployed for more than one year. What is the "old tester" for eight years?
What if the hard disk fails to recognize how to recover data
What are the uses of wireless pressure collectors?
Hyperledger Fabric 2. X custom smart contract
2022 recommended precious metal industry research report industry development prospect market analysis white paper (the attachment is a link to the online disk, and the report is continuously updated)
Use some examples of qte5
ES6 Modularization: export /import
Skills of writing test cases efficiently
Will the order of where conditions in MySQL affect the union index? Will where 1 =1 affect the use of the index? Does where 1 =1 affect the use of indexes?
Research Report on the recommended lithography industry in 2022 industry development prospect market investment analysis (the attachment is a link to the network disk, and the report is continuously u
How does MySQL implement distributed locks?
The fresh student who was born in Ali after 2000: it's really fragrant to mend this
Alphacode made its debut! The programming version of "Alpha dog" competed quietly and defeated half of the programmers