MongoDB query to skip documents

To skip documents in MongoDB, use the skip() method. This method allows you to skip a specified number of documents from the beginning of the result set, useful for pagination and result navigation.

Syntax

db.collection.find().skip(number)

Sample Data

db.demo263.insertMany([
    {_id: 100},
    {_id: 200},
    {_id: 300}
]);
{
  "acknowledged": true,
  "insertedIds": {
    "0": 100,
    "1": 200,
    "2": 300
  }
}

Display all documents from the collection ?

db.demo263.find();
{ "_id": 100 }
{ "_id": 200 }
{ "_id": 300 }

Example: Skip First 2 Documents

db.demo263.find().skip(2);
{ "_id": 300 }

Example: Combining Skip with Limit

Skip the first document and return only 1 document ?

db.demo263.find().skip(1).limit(1);
{ "_id": 200 }

Key Points

  • skip() must be used with find() or in aggregation pipelines with $skip
  • Combine with limit() for effective pagination
  • Order matters: use sort() before skip() for consistent results

Conclusion

The skip() method efficiently excludes a specified number of documents from query results. Combined with limit(), it provides powerful pagination capabilities for large datasets.

Updated on: 2026-03-15T02:09:38+05:30

253 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements