public function group($collectionName, $keys, $initial, $reduce, $options = [])
    {
        if (!($reduce instanceof Javascript)) {
            $reduce = new Javascript((string) $reduce);
        }

        if (isset($options['condition'])) {
            $options['cond'] = $this->buildCondition($options['condition']);
            unset($options['condition']);
        }

        if (isset($options['finalize'])) {
            if (!($options['finalize'] instanceof Javascript)) {
                $options['finalize'] = new Javascript((string) $options['finalize']);
            }
        }

        if (isset($options['keyf'])) {
            $options['$keyf'] = $options['keyf'];
            unset($options['keyf']);
        }
        if (isset($options['$keyf'])) {
            if (!($options['$keyf'] instanceof Javascript)) {
                $options['$keyf'] = new Javascript((string) $options['$keyf']);
            }
        }

        $document = [
            'group' => array_merge(
                [
                    'ns' => $collectionName,
                    'key' => $keys,
                    'initial' => $initial,
                    '$reduce' => $reduce,
                ],
                $options
            )
        ];

        return $document;
    }
public function group($collectionName, $keys, $initial, $reduce, $options = [])
    {
        if (!($reduce instanceof Javascript)) {
            $reduce = new Javascript((string) $reduce);
        }

        if (isset($options['condition'])) {
            $options['cond'] = $this->buildCondition($options['condition']);
            unset($options['condition']);
        }

        if (isset($options['finalize'])) {
            if (!($options['finalize'] instanceof Javascript)) {
                $options['finalize'] = new Javascript((string) $options['finalize']);
            }
        }

        if (isset($options['keyf'])) {
            $options['$keyf'] = $options['keyf'];
            unset($options['keyf']);
        }
        if (isset($options['$keyf'])) {
            if (!($options['$keyf'] instanceof Javascript)) {
                $options['$keyf'] = new Javascript((string) $options['$keyf']);
            }
        }

        $document = [
            'group' => array_merge(
                [
                    'ns' => $collectionName,
                    'key' => $keys,
                    'initial' => $initial,
                    '$reduce' => $reduce,
                ],
                $options
            )
        ];

        return $document;
    }
public function group ( $ collectionName , $ keys , $ initial , $ reduce , $ options = [ ] ) { if ( ! ( $ reduce instanceof Javascript ) ) { $ reduce = new Javascript ( ( string ) $ reduce ) ; } if ( isset ( $ options [ 'condition' ] ) ) { $ options [ 'cond' ] = $ this -> buildCondition ( $ options [ 'condition' ] ) ; unset ( $ options [ 'condition' ] ) ; } if ( isset ( $ options [ 'finalize' ] ) ) { if ( ! ( $ options [ 'finalize' ] instanceof Javascript ) ) { $ options [ 'finalize' ] = new Javascript ( ( string ) $ options [ 'finalize' ] ) ; } } if ( isset ( $ options [ 'keyf' ] ) ) { $ options [ '$keyf' ] = $ options [ 'keyf' ] ; unset ( $ options [ 'keyf' ] ) ; } if ( isset ( $ options [ '$keyf' ] ) ) { if ( ! ( $ options [ '$keyf' ] instanceof Javascript ) ) { $ options [ '$keyf' ] = new Javascript ( ( string ) $ options [ '$keyf' ] ) ; } } $ document = [ 'group' => array_merge ( [ 'ns' => $ collectionName , 'key' => $ keys , 'initial' => $ initial , '$reduce' => $ reduce , ] , $ options ) ] ; return $ document ; }
Generates 'group' command.
@param string $collectionName
@@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. If instance of [[Javascript]] passed,
it will be treated as a function that returns the key to group by.
@param array $initial Initial value of the aggregation counter object.
@param Javascript|string $reduce function that takes two arguments (the current
document and the aggregation to this point) and does the aggregation.
Argument will be automatically cast to [[Javascript]].
@param array $options optional parameters to the group command. Valid options include:
- condition - criteria for including a document in the aggregation.
- finalize - function called once per unique key that takes the final output of the reduce function.
@return array command document.
Generates group command .