Core Classes
PHP Manual

The MongoCommandCursor class

(No version information available, might only be in Git)

Introduction

A command cursor is used to iterate through the results of a database command. A command cursor is similar to a normal MongoCursor except that you use it for iterating through the result of a server command instead of a the result of a query.

You don't generally create cursors using the MongoCommandCursor constructor, you get a new cursor by calling MongoCollection::commandCursor().

Using a command cursor instead of MongoDB::command() means that you can iterate over a much larger resultset as the return of MongoDB::command() is limited to the maximum document size (currently 16MB).

Note that the cursor does not "contain" the database command results, it just manages them. Thus, if you print a cursor (with, say, var_dump() or print_r()), you'll just get the cursor object, not your documents.

Cursor Stages

A MongoCommandCursor has two "life stages": pre- and post- query. When a cursor is created, it has not yet contacted the database, so it is in its pre-query state. In this state, the client can further specify what they want the query to do, including configuring the batch size.

When the client attempts to get a result (by calling MongoCommandCursor::next(), directly or indirectly), the cursor moves into the post-command stage. At this point, the command has been executed by the database and only its batch size can be configured.

Example #1 Adding options to MongoCommandCursor

<?php

$cursor 
$collection->commandCursor(...);

// database has not yet been queried, so more options can be added
$cursor $cursor->batchSize);

var_dump($cursor->getNext());
// now database has been queried and more options cannot be added
?>

Class synopsis

MongoCommandCursor implements Iterator , MongoCursorInterface {
/* Methods */
public MongoCommandCursor batchSize ( int $batchSize )
public __construct ( MongoClient $connection , string $ns [, array $command = array() ] )
public array current ( void )
public bool dead ( void )
public array info ( void )
public string key ( void )
public void next ( void )
public array rewind ( void )
public bool valid ( void )
}

Table of Contents


Core Classes
PHP Manual