Commit 1b815c83 authored by Jens Segers's avatar Jens Segers

GroupBy implementation

parent fe7a1e85
...@@ -73,15 +73,28 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -73,15 +73,28 @@ class Query extends \Illuminate\Database\Query\Builder {
// Get Mongo cursor // Get Mongo cursor
if ($this->distinct) if ($this->distinct)
{ {
$cursor = $this->collection->distinct($this->distinct, $this->compileWheres()); return $this->collection->distinct($this->distinct, $this->compileWheres());
} }
else if(count($this->groups)) else if(count($this->groups))
{ {
$options = array(); $options = array();
$options['condition'] = $this->compileWheres(); $options['condition'] = $this->compileWheres();
$keys = array();
foreach ($this->groups as $group)
$keys[$group] = 1;
$initial = array("item" => "");
$reduce = "function (obj, prev) { prev.item = obj; }";
$result = $this->collection->group($this->groups, array(), NULL, $options); $result = $this->collection->group($keys, $initial, $reduce, $options);
$cursor = $result['retval']; $items = $result['retval'];
$results = array();
foreach($items as $item)
$results[] = $item['item'];
return $results;
} }
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment