public function count($foundOnly = false)
{
$optionNames = ['hint', 'maxTimeMS'];
if ($foundOnly) {
$optionNames = array_merge($optionNames, ['limit', 'skip']);
}
$options = $this->getOptions($optionNames) + $this->options;
try {
$count = $this->collection->count(TypeConverter::fromLegacy($this->query), $options);
} catch (\MongoDB\Driver\Exception\ExecutionTimeoutException $e) {
throw new MongoCursorTimeoutException($e->getMessage(), $e->getCode(), $e);
} catch (\MongoDB\Driver\Exception\Exception $e) {
throw ExceptionConverter::toLegacy($e);
}
return $count;
}