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.

CategoryCursor
MongoDB Version1.0+
Example Languagemongosh (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

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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏