yii\mongodb\Command::execute PHP Method

execute() public method

Executes this command.
public execute ( ) : MongoDB\Driver\Cursor
return MongoDB\Driver\Cursor result cursor.
    public function execute()
    {
        $databaseName = $this->databaseName === null ? $this->db->defaultDatabaseName : $this->databaseName;
        $token = $this->log([$databaseName, 'command'], $this->document, __METHOD__);
        try {
            $this->beginProfile($token, __METHOD__);
            $this->db->open();
            $server = $this->db->manager->selectServer($this->getReadPreference());
            $mongoCommand = new \MongoDB\Driver\Command($this->document);
            $cursor = $server->executeCommand($databaseName, $mongoCommand);
            $cursor->setTypeMap($this->db->typeMap);
            $this->endProfile($token, __METHOD__);
        } catch (RuntimeException $e) {
            $this->endProfile($token, __METHOD__);
            throw new Exception($e->getMessage(), $e->getCode(), $e);
        }
        return $cursor;
    }