<!-- llms-explorer concept facts · https://llms-explorer.com/tree/resume-from-last-key-pattern-for-killed-cursors/ · pack 2026-10-31 · ~1207 tokens -->

# Resume-from-last-key pattern for killed cursors

> Source-anchored research for Resume-from-last-key pattern for killed cursors. Run status: COMPLETED.

Parent: [Long-running secondary reads in sharded clusters](https://llms-explorer.com/tree/long-running-secondary-reads-in-sharded-clusters/) · 5 facets · 11 facts · page: https://llms-explorer.com/tree/resume-from-last-key-pattern-for-killed-cursors/

## Definitions

- ObjectId order is not guaranteed to match insertion chronology: values have one-second temporal resolution and clients can have different clocks. Consequently, an _id continuation key is an ordering boundary, not a guarantee that every document inserted later has a greater key. (low confidence) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.skip.md)

## How it works

- Engineering implication: preserve the original eligibility filter and combine it with the continuation predicate, for example {$and: [originalFilter, {_id: {$gt: lastProcessedId}}]}. Persist progress only after successful downstream processing; if a crash can occur between output and checkpoint storage, make replay idempotent or coordinate the two writes. The cited pagination sources establish the boundary mechanism, not an exactly-once processing protocol. (medium confidence) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.skip.md)

## How-to and procedures

- Prefer immutable continuation fields. Changing an ordering value while traversing can move a document across the saved boundary and cause omissions. Range continuation does not itself freeze concurrent writes or ensure that later inserts behind the boundary are included. (medium confidence) — [source](https://www.mixmax.com/engineering/api-paging-built-the-right-way)

## Problems, failure modes and limitations

- Retryable reads exclude ordinary Cursor.getMore(). The driver specification explains that after an ambiguous network failure the server might already have advanced the cursor, so blindly retrying could skip a batch; retryReads therefore does not supply ordinary cursor continuation. (high confidence) — [source](https://github.com/mongodb/specifications/blob/master/source/retryable-reads/retryable-reads.md)

## Facts and statements

- For range pagination, use a unique ordering field such as _id. The MongoDB examples query _id greater than the last-seen value with ascending sort, or less than that value with descending sort. A practitioner reports applying the ascending pattern by re-running an export query after cursor-node unavailability. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.skip.md)
- Indexed range queries avoid scanning all preceding results and usually scale better than increasingly large skip offsets. Use an index suited to the original filter and continuation ordering; the range pattern alone does not establish a constant-time guarantee for every query. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.skip.md)
- For descending sort({sortKey: -1, _id: -1}), continue with {$or: [{sortKey: {$lt: lastSortKey}}, {sortKey: lastSortKey, _id: {$lt: lastId}}]}. Keeping only the nonunique sortKey boundary can omit records tied at that value. The ordering tuple must uniquely identify each record. (high confidence) — [source](https://www.mixmax.com/engineering/api-paging-built-the-right-way)
- An export operator reports recovering from cursor-node unavailability by sorting on _id, tracking processed progress, and re-querying with _id greater than the last processed value. This is a practitioner report, not a controlled reliability test. (low confidence) — [source](https://www.reddit.com/r/mongodb/comments/1lttdef)
- In MongoDB’s descending pagination example, the forEach callback prints student.name and then assigns student._id to endValue. The helper returns endValue, and the caller passes it as the next start value. The example stores its continuation value in local variables. (low confidence) — [source](https://www.reddit.com/r/mongodb/comments/1lttdef)
- MongoDB documents range pagination by retaining the last-seen key: use {_id: {$gt: lastKey}} with sort({_id: 1}) for ascending traversal, or $lt with descending sort. Mongoose independently documents the descending pattern. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.skip.md)
- A practitioner describes handling cursor-node unavailability by sorting the export on _id, tracking the processed position, and re-running the query with _id greater than the last processed value. MongoDB’s retryable-reads specification excludes getMore from automatically retryable commands. (medium confidence) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.skip.md)
