public function sortByDimensionName($direction)
    {
        if ($this->id != '$name' && $this->id != '$value') {
            throw new AnalyticsDbException('In order to sort by dimension name, you need to first group by dimension name or dimension value.');
        }

        $direction = (int)$direction;

        if ($this->id == '$name') {
            $this->pipeline['$sort'] = ['_id' => $direction];
        } else {
            $this->pipeline['$sort'] = ['_id.name' => $direction];
        }


        return $this;
    }