Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

cursor.tailable()

On this page

  • Definition
  • Behavior
cursor.tailable()

Important

mongosh Method

This is a mongosh method. This is not the documentation for Node.js or other programming language specific driver methods.

In most cases, mongosh methods work the same way as the legacy mongo shell methods. However, some legacy methods are unavailable in mongosh.

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:

For MongoDB API drivers, refer to the language specific MongoDB driver documentation.

New in version 3.2.

Marks the cursor as tailable.

For use against a capped collection only. Using tailable() against a non-capped collection will return an error.

cursor.tailable() uses the following syntax:

cursor.tailable( { awaitData : <boolean> } )

tailable() has the following parameter:

Parameter
Type
Description
awaitData
boolean

Optional. When true, enables awaitData.

awaitData is false by default.

Returns:The cursor that tailable() is attached to.

A tailable cursor performs a collection scan over a capped collection. It remains open even after reaching the end of the collection. Applications can continue to iterate the tailable cursor as new data is inserted into the collection.

If awaitData is set to true, when the cursor reaches the end of the capped collection, MongoDB blocks the query thread for a period of time waiting for new data to arrive. When new data is inserted into the capped collection, the blocked thread is signaled to wake up and return the next batch to the client.

See Tailable Cursors.

←  cursor.sort()cursor.toArray() →

On this page