|
update : 2015.11.03
php.shukuma.com검색:
|
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. 변경점
예제Example #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"]}]
Example #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)
}
Example #3 Passing a 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 |