advancedMongoDB Performance Optimization — Explain Plan, Covered Queries & Pagination
Why does skip(N).limit(20) get slower as N grows, and what's the alternative?
skip() doesn't tell the index to start counting from a position — it tells MongoDB to return matching documents but discard the first N before returning any, so the storage engine still walks and discards all N of them every time. Cursor-based (keyset) pagination — remembering the last document's sort key and querying WHERE sort_key > last_seen_value LIMIT 20 — avoids this because it uses the index to jump straight to the right starting point.
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.
Why does skip(N).limit(20) get slower as N grows, and what's the alternative?