How to use Limit and Skip in MongoDB
This article introduces how to use Limit and Skip in MongoDB. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Detailed explanation of the use of Limit and Skip in MongoDB
A MongoDB Limit () method
If you need to read a specified number of data records in MongoDB, you can use MongoDB's Limit method, and the limit () method accepts a numeric parameter that specifies the number of records to read from MongoDB.
Grammar
The basic syntax of the limit () method is as follows:
> db.COLLECTION_NAME.find () .limit (NUMBER)
Example
> db.col.find ({}, {"title": 1) .limit (2) {"title": "PHP tutorial"} {"title": "Java tutorial"} >
Note: if you do not specify the parameters in the limit () method, all the data in the collection is displayed.
Two MongoDB Skip () method
In addition to using the limit () method to read a specified amount of data, you can also use the skip () method to skip a specified amount of data, and the skip method also accepts a numeric parameter as the number of skipped records.
Grammar
The format of the skip () method script syntax is as follows:
> db.COLLECTION_NAME.find () .limit (NUMBER) .skip (NUMBER)
Example
The above example will only display the second document data
> db.col.find ({}, {"title": 1) .limit (1) .skip (1) {"title": "Java tutorial"} so much about how to use Limit and Skip in MongoDB. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.