note 107086 added to mongocollection.group
| From: | nick at pitchinteractive dot com | Date: | Thu, 05 Jan 2012 20:51:22 +0000 |
| Subject: | note 107086 added to mongocollection.group | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185381@lists.php.net to get a copy of this message | ||
Here's my code to do an equivalent of a GROUP BY and a SUM
$contributionCol = $db->customers->contribution;
$group = $contributionCol->group(array('date' => true), array('sum' =>
0), "function (obj, prev) { prev['sum'] += obj.amount; }");
This groups by the 'date' column and sums over the 'amount' column. In my
testing this was much slower than querying all rows and doing the Group by code with PHP. It could
just be my particular setup and data set.
Also at first my amount column was a string, which caused the results to be concatenated rather than
arithmetic addition, something else to watch out for.
----
Server IP: 64.71.164.2
Probable Submitter: 69.21.197.122
----
Manual Page -- http://www.php.net/manual/en/mongocollection.group.php
Edit -- https://master.php.net/note/edit/107086
Del: integrated -- https://master.php.net/note/delete/107086/integrated
Del: useless -- https://master.php.net/note/delete/107086/useless
Del: bad code -- https://master.php.net/note/delete/107086/bad+code
Del: spam -- https://master.php.net/note/delete/107086/spam
Del: non-english -- https://master.php.net/note/delete/107086/non-english
Del: in docs -- https://master.php.net/note/delete/107086/in+docs
Del: other reasons-- https://master.php.net/note/delete/107086
Reject -- https://master.php.net/note/reject/107086
Search -- https://master.php.net/manage/user-notes.php