0
0
MongoDBquery~5 mins

skip method for offset in MongoDB

Choose your learning style9 modes available
Introduction

The skip method helps you start reading data from a specific point, ignoring the first few items. This is useful when you want to see data in parts or pages.

When showing search results page by page on a website.
When you want to ignore the first few records and see the rest.
When you are browsing a long list and want to jump to a later section.
When testing or debugging and you want to skip some initial data.
Syntax
MongoDB
db.collection.find().skip(numberToSkip)

numberToSkip is how many documents you want to ignore from the start.

Use skip together with limit to control how many documents you get back.

Examples
Skip the first 5 users and show the rest.
MongoDB
db.users.find().skip(5)
Skip 10 products, then show the next 5 products only.
MongoDB
db.products.find().skip(10).limit(5)
Skip zero documents, so this returns all orders starting from the first.
MongoDB
db.orders.find().skip(0)
Sample Program

This example adds 5 books to the collection. Then it finds all books but skips the first 2, so it returns books starting from the 3rd one.

MongoDB
db.books.insertMany([
  { title: "Book A" },
  { title: "Book B" },
  { title: "Book C" },
  { title: "Book D" },
  { title: "Book E" }
])

// Now find books skipping the first 2

const result = db.books.find().skip(2).toArray()
result
OutputSuccess
Important Notes

Skipping many documents can slow down your query because MongoDB still reads the skipped documents internally.

Always use skip with limit for pagination to avoid loading too much data at once.

Summary

skip lets you ignore a number of documents from the start.

It is useful for paging through data in chunks.

Combine skip with limit for best results.