dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Home/Error Library/mongodb-cursornotfound-exceeded-time-limit
MongoDB
MongoDB 6.0 - 8.0Queries & Cursors
6 min read
CursorNotFound: cursor id 123 not found / ExceededTimeLimit / maxTimeMS expired

MongoDB Cursor Invalidation: 10-Minute Idle Cursor Timeouts, Batch Processing & maxTimeMS Governance

Diagnosing invalidated cursor handles during slow batch consumption, tuning batchSize, and safe execution with custom cursor timeouts.

Reviewed by:Senior Database Architect & SRE (dataiotech Labs)
Tested Versions: MongoDB 6.0 / 7.0 / 8.0

Operational Verification & Reliability Metadata

Last Technical Review: 2 Kasım 2026
Tested VersionsMongoDB 7.0.8, 8.0.1
Required Privilegesread role on database
Risk Assessment
MediumNeglecting to explicitly close cursors configured with noCursorTimeout leaks server resources
Expected OutputBatch query completion within cursor lifetime using tuned batchSize
Rollback Procedure:Manually kill orphaned cursors via db.killCursors
MongoDB Docs: cursor.batchSize & Timeout
First 60 Seconds Emergency Protocol:

The error string is a symptom, not the root cause. Do not restart the server blindly. Run the diagnostic queries below to pinpoint the actual failure mode.

▸Symptom

Batch pipelines terminate after sustained execution:

plaintext
MongoServerError: cursor id not found MongoServerSelectionError: operation exceeded time limit (maxTimeMS expired)

▸What You See in Production

After consuming a portion of a dataset, workers crash at exactly the 10-minute mark.


▸Root Cause Matrix

ProbabilityRoot CauseDescription
%6510-Minute Idle Cursor ExpirationMongoDB automatically invalidates idle cursors after 10 minutes.
%25Small Default Batch SizeFetching small batches leaves cursors idle during slow client processing.
%10`maxTimeMS` Budget DepletionExecution exceeded hard query limits.

▸EMERGENCY RUNBOOK (0-5 min)

javascript
// 1. Query open cursor metrics db.serverStatus().metrics.cursor; // 2. Extend cursor timeout temporarily db.adminCommand({ setParameter: 1, cursorTimeoutMillis: 1800000 });

▸PERMANENT BLUEPRINT

  1. 1Optimal `batchSize` Tuning: Set batchSize(1000) for bulk workloads.
  2. 2Explicit Cursor Closure: When using noCursorTimeout(), always close handles in finally blocks.

▸Verification

javascript
db.serverStatus().metrics.cursor.open;

Other Database Error Triage Playbooks

Other battle-tested diagnostic guides for high-severity database errors.

All Errors (82)