LMongo\Query\Builder::group PHP Method

group() public method

Execute a group command on the database.
public group ( array $initial, mixed $reduce, mixed $columns = [], array $options = [] ) : LMongo\Query\Cursor
$initial array
$reduce mixed
$columns mixed
$options array
return LMongo\Query\Cursor
    public function group(array $initial, $reduce, $columns = array(), array $options = array())
    {
        if (is_null($this->columns)) {
            $this->columns = $columns;
        }
        if (is_string($this->columns)) {
            $this->columns = new \MongoCode($this->columns);
        }
        if (is_string($reduce)) {
            $reduce = new \MongoCode($reduce);
        }
        $conditions = $this->compileWheres($this);
        if (count($conditions)) {
            $options['condition'] = $conditions;
        }
        if (isset($options['finalize']) and is_string($options['finalize'])) {
            $options['finalize'] = new \MongoCode($options['finalize']);
        }
        if (empty($options)) {
            $result = $this->connection->{$this->collection}->group($this->columns, $initial, $reduce);
        } else {
            $result = $this->connection->{$this->collection}->group($this->columns, $initial, $reduce, $options);
        }
        if (!$result['ok']) {
            throw new \MongoException($result['errmsg']);
        }
        return $result['retval'];
    }
Builder