Sets whether this cursor will wait for a while for a tailable cursor to return more data

# MongoCursor::awaitData

(PECL mongo >=1.2.11)

MongoCursor::awaitData — Sets whether this cursor will wait for a while for a tailable cursor to return more data

### Descrierea

public MongoCursor::awaitData ([ bool `$wait` = `TRUE` ] ) : MongoCursor

This method is to be used with tailable cursors. If we are at the end of the data, block for a while rather than returning no data. After a timeout period, we do return as normal.

### Parametri

`wait`

  If the cursor should wait for more data to become available.

### Valorile întoarse

Returns this cursor.

### Erori/Excepții

Throws MongoCursorException if this cursor has started iterating.

### Exemple

Example #1 MongoCursor::awaitData() example

In this example we tail the "oplog" and instead of sleeping during every iteration, we set the MongoCursor::awaitData() option. MongoCursor::hasNext() will now block until there is more data available.

`<?php
$m = new MongoClient( 'mongodb://localhost:13000', array( 'replSet' => 'seta' ) );
$c = $m->local->selectCollection( 'oplog.rs' );
$cursor = $c->find( array( 'ns' => 'demo.article', 'op' => 'i' ) );
$cursor->tailable( true );
$cursor->awaitData( true );
while (true) {
if (!$cursor->hasNext()) {
// we've read all the results, exit
if ($cursor->dead()) {
break;
}
} else {
var_dump( $cursor->getNext() );
}
}
?>`

### A se vedea și

MongoDB core docs on » tailable cursors.

- MongoCursor::tailable() - Sets whether this cursor will be left open after fetching the last results