MongoDB Limit and Skip method

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
  1. > db.col.find({},{"title":1,_id:0}).limit(2)
  2. { "title" : "PHP 教程" }
  3. { "title" : "Java 教程" }
  4. >
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
  1. >db.col.find({},{"title":1,_id:0}).limit(1).skip(1)
  2. { "title" : "Java 教程" }
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327094194&siteId=291194637