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.

Syntax

Basic syntax of limit() method is as follows

Example

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.

Syntax

Basic syntax of skip() method is as follows

Example

Below example will display only the second document.

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

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

MongoDB Topics