本文整理汇总了PHP中MongoCollection::aggregateCursor方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCollection::aggregateCursor方法的具体用法?PHP MongoCollection::aggregateCursor怎么用?PHP MongoCollection::aggregateCursor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCollection
的用法示例。
在下文中一共展示了MongoCollection::aggregateCursor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mkonereg
function mkonereg($db, $colname, $grouparr)
{
$ops = array();
// $ops[] = ['$match' => $query];
// $ops[] = ['$sort' => ['year'=> -1, 'month'=> -1]];
$ops[] = ['$group' => $grouparr];
$option = ['allowDiskUse' => true];
//print_r($ops);
$collection = new MongoCollection($db, $colname);
echo "working on: {$colname} ... with";
$col2name = $colname . "_reg";
$col2 = new MongoCollection($db, $col2name);
print_r($grouparr['_id']);
makegrpIndex($db, $col2, $grouparr['_id']);
//print_r($ops);
try {
$cursor = $collection->aggregateCursor($ops, $option);
} catch (MongoException $e) {
echo "error message: " . $e->getMessage() . "\n";
echo "error code: " . $e->getCode() . "\n";
exit(1);
}
//$results = $cursor['result'];
foreach ($cursor as $result) {
//print_r($result[_id]);
$col2->insert($result['_id']);
}
}
示例2: down
/**
* Convert foreign id values from MongoId to string.
*
* @return void
*/
public function down()
{
// The Client model has a mutator that converts lrs_id from string to MongoId,
// so the Mongo classes are used to directly modify the client collection.
$db = \DB::getMongoDB();
$clients = new MongoCollection($db, 'client');
$lrsIds = $clients->aggregateCursor([['$group' => ['_id' => '$lrs_id']]]);
foreach ($lrsIds as $lrsId) {
$clients->update(['lrs_id' => $lrsId['_id']], ['$set' => ['lrs_id' => (string) $lrsId['_id']]], ['multiple' => true]);
}
echo 'Foreign id values in client collection converted from MongoId to string.' . PHP_EOL;
}
示例3: findMostReportedCommentary
/**
* Retrieves an iterator on a list of abusive Commentary
*
* @param int $offset
* @param int $limit
*
* @return \MongoCursor
*/
public function findMostReportedCommentary($offset = 0, $limit = 20)
{
return $this->collection->aggregateCursor([['$match' => ['commentary.0' => ['$exists' => true], 'commentary' => ['$elemMatch' => ['abusiveCount' => ['$gt' => 0]]]]], ['$unwind' => '$commentary'], ['$match' => ['commentary.abusiveCount' => ['$gt' => 0]]], ['$project' => ['commentary' => true]], ['$sort' => ['commentary.abusiveCount' => -1]]]);
// I love arrays
}