protected function aggregate($column, $operator, $db)
{
$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'];
} else {
return 0;
}
}