cursor.tailable()

Definition

  • cursor.tailable()

mongo Shell Method

This page documents the mongo shell method, and doesnot refer to the MongoDB Node.js driver (or any other driver)method. For corresponding MongoDB driver API, refer to your specificMongoDB driver documentation instead.

New in version 3.2.

Marks the cursor as tailable.

For use against a capped collection only. Usingtailable against a non-capped collection will returnan error.

cursor.tailable() uses the following syntax:

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

tailable() has the following parameter:

ParameterTypeDescriptionawaitDatabooleanOptional. When true, enables awaitData.

awaitData is false by default.

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

Behavior

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 asnew data is inserted into the collection.

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

See Tailable Cursors.