MongoCommandCursor
PHP Manual

MongoCommandCursor::__construct

(PECL mongo >=1.5.0)

MongoCommandCursor::__constructCreate a new command cursor

Description

public MongoCommandCursor::__construct ( MongoClient $connection , string $ns [, array $command = array() ] )

In many instances, you do not have to create a MongoCommandCursor manually, but instead one of the helper functions such as MongoCollection::aggregateCursor() and MongoCollection::parallelCollectionScan(). However, if the server adds new commands that can return cursors, then manually creating MongoCommandCursor objects is required. However, it might be easier to use the MongoCommandCursor::createFromDocument() instead.

Parameters

connection

Database connection.

ns

Full name of database and collection.

command

Database command.

Return Values

Returns the new cursor.

Examples

Example #1 MongoCommandCursor() example

<?php
$m 
= new MongoClient;
$d $m->demo;

// setup the pipeline
$pipeline = [
    [ 
'$group' => [
        
'_id' => '$country_code',
        
'timezones' => [ '$addToSet' => '$timezone' ]
    ] ],
    [ 
'$sort' => [ '_id' => ] ],
];

// run the command, and return a MongoCommandCursor object
$r $d->commandCursor(
    
$m// MongoClient object
    
'demo.cities'// namespace
    
[
        
'aggregate' => 'cities',
        
'pipeline' => $pipeline,
    ]
);

foreach(
$r as $document) {
   

}
?>

See Also


MongoCommandCursor
PHP Manual