Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

cursor.tailable()

On this page

  • Definition
  • Behavior
cursor.tailable()

Important

mongo Shell Method

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

New in version 3.2.

Marks the cursor as tailable keeping it open even when the client exhausts all results.

For use against a capped collection only. Using ~cursor.tailable() against a non-capped collection returns an error.

cursor.tailable() uses the following syntax:

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

~cursor.tailable() has the following parameter:

Parameter
Type
Description
awaitData
boolean

Optional. For use with DBQuery.Option.tailable. Sets the cursor to block the query thread when no data is available and await data for a set time instead of immediately returning no data. The cursor returns no data only if the timeout expires.

By default, if maxTimeMS is set on the command that created the cursor, then the timeout for awaitData is the remaining time. Otherwise, the default timeout is 1000 milliseconds.

You can set a timeout when running getMore on a cursor with awaitData enabled.

Defaults to false.

Returns:The cursor that ~cursor.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 true, when the cursor reaches the end of the capped collection, mongod blocks the query thread for the timeout interval and waits for new data to arrive. When new data is inserted into the capped collection, mongod signals the blocked thread to wake and return the next batch to the client.

See Tailable Cursors.

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

On this page