tailable() (Tailable Cursor)

Last updated: 2026-10-09

tailable() (Tailable Cursor)

tailable() marks a cursor as tailable, e.g. `db.logs.find().tailable()`. Instead of closing when data runs out, a tailable cursor keeps waiting for new documents — used to tail logs and watch for inserts before Change Streams existed. It requires a capped collection; in replica sets it pairs well with the awaitData option.

CategoryCursor
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

db.<collection>.find(<filter>).tailable({ awaitData: <bool> })

⚙️ Parameters

awaitDataOptional. true blocks for new data instead of returning immediately.

Returns:The cursor marked tailable (chainable).

▶ Example

Run the commands below in your local mongosh (requires a running mongod):

// tailable: keep reading new log entries
const cursor = db.logs.find()
  .tailable({ awaitData: true })
while (cursor.hasNext()) {
  print(cursor.next().msg)
}

Output:

login ok
order created
payment received

📌 Notes

More hands-on cases coming soon.

📚 Related Tutorials

❓ FAQ

QWhat are tailable cursors for?
AThey keep reading new data from capped collections — real-time log tailing and monitoring streams — without closing at the end.
QWhat are tailable's limitations?
ACapped collections only; new projects should use watch() Change Streams, which are richer and work on normal collections.
QHow does tailable differ from watch?
Atailable() polls new data on capped collections; watch() uses the oplog Change Stream, supporting normal collections and more event types.
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%

🙏 帮我们做得更好

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

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