Resume-from-last-key pattern for killed cursors
Parent: Long-running secondary reads in sharded clusters · Published reference · snapshot 2026-10-31
↓ Facts as markdownall context files
Source-anchored research for Resume-from-last-key pattern for killed cursors. Run status: COMPLETED.
These notes link each claim to its source. Some citations identify archived research reports that are no longer hosted on this site. A published reference means the content is available; it does not certify independent review or accuracy.Read the editorial policy and follow the sources before relying on a claim.
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]
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]
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]
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]
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]
- 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]
- 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]
- 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]
- 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]
- 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]
- 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]
Children
- No children recorded.