yii\mongodb\Command::query PHP Method

query() public method

Executes this command as a mongo query
public query ( string $collectionName, array $options = [] ) : MongoDB\Driver\Cursor
$collectionName string collection name
$options array query options.
return MongoDB\Driver\Cursor result cursor.
    public function query($collectionName, $options = [])
    {
        $databaseName = $this->databaseName === null ? $this->db->defaultDatabaseName : $this->databaseName;
        $token = $this->log('find', array_merge(['ns' => $databaseName . '.' . $collectionName, 'filter' => $this->document], $options), __METHOD__);
        $readConcern = $this->getReadConcern();
        if ($readConcern !== null) {
            $options['readConcern'] = $readConcern;
        }
        try {
            $this->beginProfile($token, __METHOD__);
            $query = new \MongoDB\Driver\Query($this->document, $options);
            $this->db->open();
            $server = $this->db->manager->selectServer($this->getReadPreference());
            $cursor = $server->executeQuery($databaseName . '.' . $collectionName, $query);
            $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;
    }