php教程

MongoCommandCursor::__construct

(PECL mongo >=1.5.0)

MongoCommandCursor::__constructCreate a new command cursor

说明

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

Generally, you should not have to construct a MongoCommandCursor manually, as there are helper functions such as MongoCollection::aggregateCursor() and MongoCollection::parallelCollectionScan(); however, if the server introduces new commands that can return cursors, this constructor will be useful in the absence of specific helper methods. You may also consider using MongoCommandCursor::createFromDocument().

参数

connection

Database connection.

ns

Full name of the database and collection (e.g. "test.foo")

command

Database command.

返回值

Returns the new cursor.

范例

Example #1 MongoCommandCursor example

<?php
$m 
= new MongoClient;

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

// Construct a MongoCommandCursor object
$cursor = new MongoCommandCursor(
    
$m// MongoClient object
    
'demo.cities'// namespace
    
[
        
'aggregate' => 'cities',
        
'pipeline' => $pipeline,
        
'cursor' => [ 'batchSize' => ],
    ]
);

foreach(
$cursor as $result) {
   
...
}
?>

参见

User Contributed Notes

There are no user contributed notes for this page.

CopyRight © 2008-2022 verySource.Com All Rights reserved. 京ICP备17048824号-1 京公网安备:11010502034788