|
MongoCollection::group(PECL mongo >=0.9.2) MongoCollection::group — Performs an operation similar to SQL's GROUP BY command ОписаниеСписок параметров
Возвращаемые значенияReturns an array containing the result. ПримерыПример #1 MongoCollection::group() example This groups documents by category and creates a list of names within that category.
<?php Результатом выполнения данного примера будет что-то подобное: [{"category":"fruit","items":["apple","peach","banana"]},{"category":"veggie","items":["corn","broccoli"]}] Пример #2 MongoCollection::group() example This example doesn't use any key, so every document will be its own group. It also uses a condition: only documents that match this condition will be processed by the grouping function.
<?php Результатом выполнения данного примера будет что-то подобное: array(4) { ["retval"]=> array(1) { [0]=> array(1) { ["count"]=> float(1) } } ["count"]=> float(1) ["keys"]=> int(1) ["ok"]=> float(1) } Пример #3 Passing a keys function If you want to group by something other than a field name, you can pass a function as the first parameter of MongoCollection::group() and it will be run against each document. The return value of the function will be used as its grouping value. This example demonstrates grouping by the num field modulo 4.
<?php |
|