public function getNumBytes($user = null)
{
try {
$pipeline = [['$group' => ['_id' => null, 'numBytes' => ['$sum' => '$size']]]];
if ($user) {
array_unshift($pipeline, ['$match' => ['user' => $user]]);
}
$result = $this->getImageCollection()->aggregate($pipeline, ['useCursor' => false]);
if (!count($result)) {
return 0;
}
return (int) $result[0]->numBytes;
} catch (MongoException $e) {
throw new DatabaseException('Unable to fetch information from the database', 500, $e);
}
}