(PECL mongo >=0.9.4)

MongoCursor::tailableSets whether this cursor will be left open after fetching the last results


public MongoCursor MongoCursor::tailable ([ bool $tail = true ] )

Mongo has a feature known as tailable cursors which are similar to the Unix "tail -f" command.

Tailable means cursor is not closed when the last data is retrieved. Rather, the cursor marks the final object's position. you can resume using the cursor later, from where it was located, if more data were received.

Like any "latent cursor", the cursor may become invalid at some point -- for example if that final object it references were deleted. Thus, you should be prepared to requery if the cursor is MongoCursor::dead().



If the cursor should be tailable.

Значення, що повертаються

Returns this cursor.


Throws MongoCursorException if this cursor has started iterating.


Приклад #1 MongoCursor::tailable() example



$results = array();

while (
1) {
    if (!
$cursor->hasNext()) {
// we've read all the results, exit
if ($cursor->dead()) {
// read all results so far, wait for more
    else {
$results[] = $cursor->getNext();


Прогляньте Також

MongoDB core docs on » tailable cursors.

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top