In this MongoDB Tutorial, we shall learn to skip a specified number of records that a query returns in the result.

MongoDB Skip Documents

MongoDB Skip Documents – To skip first N number of records that a query returns in the result, use cursor.skip() method. Skip method accepts a number as argument which indicates the starting number of records to be skipped in the query result.

Syntax of skip method

Following is the syntax of skip method :

When no value is provided, no documents are skipped, else the value provided in the argument would be considered.

Note : db.collection.find() returns cursor to the records. And skip() method can be applied on this cursor to skip the first N number of records as shown below :

 

Example : With a number as argument to skip method

Only two documents, as provided to the skip method, are skipped in the result.

 

Example : With nothing provided as argument to skip method

All documents are fetched in the result.

 

Conclusion

In this tutorial – MongoDB Skip Documents, we have learnt to skip first N number of documents returned in the result. In our next tutorial, we shall learn to sort documents.