MONGOCOMMANDCURSOR.__CONSTRUCT(3) 1 MONGOCOMMANDCURSOR.__CONSTRUCT(3)
MongoCommandCursor::__construct - Create a new command cursor
SYNOPSIS
public MongoCommandCursor::__construct (MongoClient $connection, string $ns, array $command = array())
DESCRIPTION
Generally, you should not have to construct a MongoCommandCursor manually, as there are helper functions such as MongoCollection::aggre-
gateCursor and MongoCollection::parallelCollectionScan; however, if the server introduces new commands that can return cursors, this con-
structor will be useful in the absence of specific helper methods. You may also consider using MongoCommandCursor::createFromDocument.
PARAMETERS
o $connection
- Database connection.
o $ns
- Full name of the database and collection (e.g. "test.foo")
o $command
- Database command.
RETURN VALUES
Returns the new cursor.
EXAMPLES
Example #1
MongoCommandCursor example
<?php
$m = new MongoClient;
// Define the aggregation pipeline
$pipeline = [
[ '$group' => [
'_id' => '$country_code',
'timezones' => [ '$addToSet' => '$timezone' ]
] ],
[ '$sort' => [ '_id' => 1 ] ],
];
// Construct a MongoCommandCursor object
$cursor = new MongoCommandCursor(
$m, // MongoClient object
'demo.cities', // namespace
[
'aggregate' => 'cities',
'pipeline' => $pipeline,
'cursor' => [ 'batchSize' => 0 ],
]
);
foreach($cursor as $result) {
}
?>
SEE ALSO
MongoCommandCursor.createFromDocument(3), MongoCollection.aggregateCursor(3), MongoCollection.parallelCollectionScan(3).
PHP Documentation Group MONGOCOMMANDCURSOR.__CONSTRUCT(3)