Facebook Pixel

What is the difference between offset and cursor pagination?

Offset uses skip and limit; client can jump to any page; slow for large offsets. Cursor uses a cursor field (e.g., createdAt); client can only go next/prev; fast for large collections; stable when new items are inserted.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Offset Pagination vs Cursor Pagination in MongoDB

For large collections (> 10000 docs) or infinite scroll. Cursor is fast because MongoDB uses an index on the cursor field. It is stable: new items do not cause duplicates or skips between requests.

For small collections or when the client needs page numbers ('showing 1-20 of 432'). Offset is simple and lets the client jump to any page. Slow for large offsets because MongoDB scans the skipped docs.

MongoDB still scans the skipped documents before returning the ones you want. For offset 100000, it scans 100000 docs. Use cursor-based pagination instead: find documents where createdAt is less than the last cursor. MongoDB uses an index.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.