A MongoDB Limit() method
If you need to read a specified number of data records in MongoDB, you can use MongoDB's Limit method. 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,_id:0}).limit(2)
{ "title" : "PHP 教程" }
{ "title" : "Java 教程" }
>
Note: If you do not specify parameters in the limit() method, all data in the collection will be 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. The skip method also accepts a numeric parameter as the number of skipped records.
grammar
The syntax of the skip() method script 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,_id:0}).limit(1).skip(1)
{ "title" : "Java 教程" }