Manager/GenericDocumentManager.php
public function aggregateGroup($group, $match = [], $query = null, $sort = null, $limit = null)
    {
        $query = $this->getDefault('query', $query);

        $collection = $this->dm->getDocumentCollection($this->document);

        $pipeline = [];

        if ($query) {
            $query = $this->addNativeQuery($this->queryFields, $query);
            $match = array_merge($match, $query);
        }


        if (count($match)) {
            $pipeline[] = [
                '$match' => $match
            ];
        }

        $pipeline[] = [
            '$group' => $group
        ];

        if ($sort) {
            $pipeline[] = [
                '$sort' => $sort
            ];
        }

        if ($limit) {
            $pipeline[] = [
                '$limit' => $limit
            ];
        }

        $return = $collection->aggregate($pipeline);

        return iterator_to_array($return);
    }
public function aggregateGroup($group, $match = [], $query = null, $sort = null, $limit = null)
    {
        $query = $this->getDefault('query', $query);

        $collection = $this->dm->getDocumentCollection($this->document);

        $pipeline = [];

        if ($query) {
            $query = $this->addNativeQuery($this->queryFields, $query);
            $match = array_merge($match, $query);
        }


        if (count($match)) {
            $pipeline[] = [
                '$match' => $match
            ];
        }

        $pipeline[] = [
            '$group' => $group
        ];

        if ($sort) {
            $pipeline[] = [
                '$sort' => $sort
            ];
        }

        if ($limit) {
            $pipeline[] = [
                '$limit' => $limit
            ];
        }

        $return = $collection->aggregate($pipeline);

        return iterator_to_array($return);
    }
Aggregate with custom group

@param mixed $collection
@param mixed $fieldGroup
@param mixed $match

@return array Multidimensional array with key => sum per item