PHP » GoLang |
login |
register |
about
|
GoLang MongoCollection::group
request it (412)
GoLang replacement for PHP's MongoCollection::group
[edit | history]
MongoCollection::group(PECL mongo >=0.9.2) MongoCollection::group — Performs an operation similar to SQL's GROUP BY command DescriptionParameters
Return ValuesReturns an array containing the result. Changelog
ExamplesExample #1 MongoCollection::group() example This groups documents by category and creates a list of names within that category.
<?php The above example will output something similar to: [{"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 The above example will output something similar to: 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 |
more
Recently updated
more
Most requested
more
Last requests
|