noCursorTimeout() (Disable Cursor Timeout)
Last updated: 2026-10-09
noCursorTimeout() (Disable Cursor Timeout)
noCursorTimeout() disables a cursor's server-side idle timeout: `db.users.find().noCursorTimeout()`. By default, cursors idle past ten minutes get reaped; with this flag a cursor can live long — handy for slow consumers of big batches. Warning: long-lived cursors hold server resources, so close() them manually when done to avoid leaks.
| Category | Cursor |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
db.<collection>.find(<filter>).noCursorTimeout()
Returns:The cursor with timeout disabled (chainable).
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// noCursorTimeout: long-running walk of a big collection
const cursor = db.logs.find().noCursorTimeout().batchSize(100)
cursor.forEach(doc => processDoc(doc))
cursor.close()
Output:
(iteration completed, no output)
📌 Notes
- The default idle timeout is ten minutes; noCursorTimeout() cancels it
- Long-lived cursors hold server memory — always close()
- Pair with batchSize() to control batch sizes
🏷️ Related Tags
💡 Related Cases
More hands-on cases coming soon.
📚 Related Tutorials
❓ FAQ
QWhat is the default cursor timeout?
AThe server reaps idle cursors after ten minutes; noCursorTimeout() disables that.
QWhat should I watch out for with noCursorTimeout?
AAlways close() the cursor when done or when exiting early, or server resources leak.
QWhen do I need noCursorTimeout?
ASlow batch jobs that may run past ten minutes per cursor, such as cleaning millions of documents one by one.