/**
* Execute a database command
*
* @link http://www.php.net/manual/en/mongodb.command.php
* @param array $data The query to send.
* @param array $options
* @return array Returns database response.
*/
public function command(array $data, $options = [], &$hash = null)
{
try {
$cursor = new \MongoCommandCursor($this->connection, $this->name, $data);
$cursor->setReadPreference($this->getReadPreference());
return iterator_to_array($cursor)[0];
} catch (\MongoDB\Driver\Exception\Exception $e) {
return ExceptionConverter::toResultArray($e);
}
}