public function group($keys, array $initial, $reduce, array $condition = [])
    {
        if (is_string($reduce)) {
            $reduce = new MongoCode($reduce);
        }

        $command = [
            'group' => [
                'ns' => $this->name,
                '$reduce' => (string) $reduce,
                'initial' => $initial,
                'cond' => $condition,
            ],
        ];

        if ($keys instanceof MongoCode) {
            $command['group']['$keyf'] = (string) $keys;
        } else {
            $command['group']['key'] = $keys;
        }
        if (array_key_exists('condition', $condition)) {
            $command['group']['cond'] = $condition['condition'];
        }
        if (array_key_exists('finalize', $condition)) {
            if ($condition['finalize'] instanceof MongoCode) {
                $condition['finalize'] = (string) $condition['finalize'];
            }
            $command['group']['finalize'] = $condition['finalize'];
        }

        return $this->db->command($command);
    }
public function group($keys, array $initial, $reduce, array $condition = [])
    {
        if (is_string($reduce)) {
            $reduce = new MongoCode($reduce);
        }

        $command = [
            'group' => [
                'ns' => $this->name,
                '$reduce' => (string) $reduce,
                'initial' => $initial,
                'cond' => $condition,
            ],
        ];

        if ($keys instanceof MongoCode) {
            $command['group']['$keyf'] = (string) $keys;
        } else {
            $command['group']['key'] = $keys;
        }
        if (array_key_exists('condition', $condition)) {
            $command['group']['cond'] = $condition['condition'];
        }
        if (array_key_exists('finalize', $condition)) {
            if ($condition['finalize'] instanceof MongoCode) {
                $condition['finalize'] = (string) $condition['finalize'];
            }
            $command['group']['finalize'] = $condition['finalize'];
        }

        return $this->db->command($command);
    }
public function group ( $ keys , array $ initial , $ reduce , array $ condition = [ ] ) { if ( is_string ( $ reduce ) ) { $ reduce = new MongoCode ( $ reduce ) ; } $ command = [ 'group' => [ 'ns' => $ this -> name , '$reduce' => ( string ) $ reduce , 'initial' => $ initial , 'cond' => $ condition , ] , ] ; if ( $ keys instanceof MongoCode ) { $ command [ 'group' ] [ '$keyf' ] = ( string ) $ keys ; } else { $ command [ 'group' ] [ 'key' ] = $ keys ; } if ( array_key_exists ( 'condition' , $ condition ) ) { $ command [ 'group' ] [ 'cond' ] = $ condition [ 'condition' ] ; } if ( array_key_exists ( 'finalize' , $ condition ) ) { if ( $ condition [ 'finalize' ] instanceof MongoCode ) { $ condition [ 'finalize' ] = ( string ) $ condition [ 'finalize' ] ; } $ command [ 'group' ] [ 'finalize' ] = $ condition [ 'finalize' ] ; } return $ this -> db -> command ( $ command ) ; }
Performs an operation similar to SQL's GROUP BY command

@link http://www.php.net/manual/en/mongocollection.group.php
@param mixed $keys Fields to group by. If an array or non-code object is passed, it will be the key used to group results.
@param array $initial Initial value of the aggregation counter object.
@param MongoCode|string $reduce A function that aggregates (reduces) the objects iterated.
@param array $condition An condition that must be true for a row to be considered.
@return array
Performs an operation similar to SQL s GROUP BY command