public function database(string $database = null): MongoDatabase
    {
        if (empty($database)) {
            $database = $this->config->defaultDatabase();
        }

        //Spiral support ability to link multiple virtual databases together using aliases
        $database = $this->config->resolveAlias($database);

        if (isset($this->databases[$database])) {
            return $this->databases[$database];
        }

        if (!$this->config->hasDatabase($database)) {
            throw new ODMException(
                "Unable to initiate MongoDatabase, no presets for '{$database}' found"
            );
        }

        $options = $this->config->databaseOptions($database);

        //Initiating database instance
        return $this->createDatabase(
            $database,
            $options['server'],
            $options['database'],
            $options['driverOptions'] ?? [],
            $options['options'] ?? []
        );
    }
public function database(string $database = null): MongoDatabase
    {
        if (empty($database)) {
            $database = $this->config->defaultDatabase();
        }

        //Spiral support ability to link multiple virtual databases together using aliases
        $database = $this->config->resolveAlias($database);

        if (isset($this->databases[$database])) {
            return $this->databases[$database];
        }

        if (!$this->config->hasDatabase($database)) {
            throw new ODMException(
                "Unable to initiate MongoDatabase, no presets for '{$database}' found"
            );
        }

        $options = $this->config->databaseOptions($database);

        //Initiating database instance
        return $this->createDatabase(
            $database,
            $options['server'],
            $options['database'],
            $options['driverOptions'] ?? [],
            $options['options'] ?? []
        );
    }
public function database ( string $ database = null ) : MongoDatabase { if ( empty ( $ database ) ) { $ database = $ this -> config -> defaultDatabase ( ) ; } //Spiral support ability to link multiple virtual databases together using aliases $ database = $ this -> config -> resolveAlias ( $ database ) ; if ( isset ( $ this -> databases [ $ database ] ) ) { return $ this -> databases [ $ database ] ; } if ( ! $ this -> config -> hasDatabase ( $ database ) ) { throw new ODMException ( "Unable to initiate MongoDatabase, no presets for '{$database}' found" ) ; } $ options = $ this -> config -> databaseOptions ( $ database ) ; //Initiating database instance return $ this -> createDatabase ( $ database , $ options [ 'server' ] , $ options [ 'database' ] , $ options [ 'driverOptions' ] ?? [ ] , $ options [ 'options' ] ?? [ ] ) ; }
Create specified or select default instance of MongoDatabase.

@param string $database Database name (internal).

@return MongoDatabase

@throws ODMException
Create specified or select default instance of MongoDatabase .