MongoDB Tutorial - MongoDB Limit/Skip Records








Limit() Method

To limit the records in MongoDB, use limit() method. limit() method accepts one number type argument, which is number of documents to return.

The syntax of limit() method is as follows

>db.COLLECTION_NAME.find().limit(NUMBER)

The following example displays 2 documents.

>db.mycol.find({},{"title":1,_id:0}).limit(2)
>

By default limit() method will display all documents from the collection without parameter.

Skip() Method

skip() accepts number type argument and skips number of documents.

The syntax of skip() method is as follows

>db.COLLECTION_NAME.find().limit(NUMBER).skip(NUMBER)

The following query displays only second found document.

>db.mycol.find({},{"title":1,_id:0}).limit(1).skip(1)
{"title":"NoSQL Overview"}
>