protected function aggregate($column, $operator, $db)
    {
        if (!empty($this->emulateExecution)) {
            return null;
        }

        $this->prepare();
        $collection = $this->getCollection($db);
        $pipelines = [];
        if ($this->where !== null) {
            $pipelines[] = ['$match' => $this->where];
        }
        $pipelines[] = [
            '$group' => [
                '_id' => '1',
                'total' => [
                    '$' . $operator => '$' . $column
                ],
            ]
        ];
        $result = $collection->aggregate($pipelines);
        if (array_key_exists(0, $result)) {
            return $result[0]['total'];
        }
        return null;
    }
protected function aggregate($column, $operator, $db)
    {
        if (!empty($this->emulateExecution)) {
            return null;
        }

        $this->prepare();
        $collection = $this->getCollection($db);
        $pipelines = [];
        if ($this->where !== null) {
            $pipelines[] = ['$match' => $this->where];
        }
        $pipelines[] = [
            '$group' => [
                '_id' => '1',
                'total' => [
                    '$' . $operator => '$' . $column
                ],
            ]
        ];
        $result = $collection->aggregate($pipelines);
        if (array_key_exists(0, $result)) {
            return $result[0]['total'];
        }
        return null;
    }
protected function aggregate ( $ column , $ operator , $ db ) { if ( ! empty ( $ this -> emulateExecution ) ) { return null ; } $ this -> prepare ( ) ; $ collection = $ this -> getCollection ( $ db ) ; $ pipelines = [ ] ; if ( $ this -> where !== null ) { $ pipelines [ ] = [ '$match' => $ this -> where ] ; } $ pipelines [ ] = [ '$group' => [ '_id' => '1' , 'total' => [ '$' . $ operator => '$' . $ column ] , ] ] ; $ result = $ collection -> aggregate ( $ pipelines ) ; if ( array_key_exists ( 0 , $ result ) ) { return $ result [ 0 ] [ 'total' ] ; } return null ; }
Performs the aggregation for the given column.
@param string $column column name.
@param string $operator aggregation operator.
@param Connection $db the database connection used to execute the query.
@return int aggregation result.
Performs the aggregation for the given column .