MongoDB Limit Records - MongoDB

How to limit records in MongoDB?

In this chapter, we will explain you how to limit records using MongoDB.

Limit() Method

Limit() method is used to limit the records in MongoDB. This method accepts one number type argument which is the number of documents which you want to displayed.


Basic syntax of limit() method is as follows


Consider collection myycol has below data.

Below example will display only two documents while querying the document.

If the number argument in limit() method is not specified, then it will display all documents from the collection.

MongoDB Skip() Method

Apart from limit() method, skip() method also accepts number type argument and is used to skip the number of documents.


Basic syntax of skip() method is as follows


Below example will display only the second document.

Remember that the default value in skip() method is 0.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

MongoDB Topics