Add new database in a database pull, database name will be automatically selected from given
instance.

@param string        $name Internal database name.
@param MongoDatabase $database

@return self|$this

@throws ODMException
509512
public function addDatabase(string $name, MongoDatabase $database): MongoManager
    {
        if (isset($this->databases[$name])) {
            throw new ODMException("Database '{$name}' already exists");
        }

        $this->databases[$name] = $database;

        return $this;
    }
744230
public function getDatabaseMap($name = null)
    {
        if (null === $name) {
            $name = $this->getDefaultDatasource();
        }
        if (!isset($this->databaseMaps[$name])) {
            $class = $this->databaseMapClass;
            $this->databaseMaps[$name] = new $class($name);
        }

        return $this->databaseMaps[$name];
    }
1135511
public function setDatabase($database)
    {
        if (!$this->_connection->select_db($database)) {
            throw new AnDatabaseException('Could not connect with database : '.$database);
        }

        $this->_database = $database;
        return $this;
    }
871770
public function setDatabase($database)
    {
        if (! $database instanceof MongoDB) {
            $database = $this->connection->getConnection()->{$database};
        }

        $this->database = $database;

        return $this;
    }
1098616
public function setDatabase(Index $database)
    {
        $this->database = $database;
        
        //for each row
        foreach ($this->list as $row) {
            if (!is_object($row) || !method_exists($row, __FUNCTION__)) {
                continue;
            }
            
            //let the row handle this
            $row->setDatabase($database);
        }
        
        return $this;
    }
785647
public static MongoDatabase createDatabaseProxy(final MongoDatabase database) {
		if (DISABLED) {
			return database;
		}
		SERVICES_COUNTER.setDisplayed(!COUNTER_HIDDEN);
		SERVICES_COUNTER.setUsed(true);
		return JdbcWrapper.createProxy(database, new MongoDatabaseHandler(database));
	}
1217588
public function setDatabase(Database $database)
    {
        $this->database = $database;
        $identity = $database->identity();
        $this->cacheKey = sprintf(
            self::CACHE_KEY_TEMPLATE,
            $identity['projectId'],
            $identity['instance'],
            $identity['database']
        );

        if (!isset($this->config['lock'])) {
            $this->config['lock'] = $this->getDefaultLock();
        }
    }
1058133
public function selectCollection($db, $collection)
    {
        $this->initialize();
        return $this->selectDatabase($db)->selectCollection($collection);
    }
27087
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'] ?? []
        );
    }
1254776
public function selectDB($name)
    {
        $this->dbname = $name;

        if ($this->state !== 1) {
            return $this->query('USE `' . $name . '`');
        }

        return true;
    }
103642
protected function createDatabaseDriver(string $name, Prop $config)
	{
		return new DatabaseStore(
			App::Database()->getConnection($config->getOr("connection", null)),
			$name,
			$config->getOr("table", "cache"),
			$config->getOr("life", 0)
		);
	}
226937
protected function setDatabase($name) {
        if (isset($name) && !is_string($name)) throw new IllegalTypeException('Illegal type of parameter $name: '.gettype($name));
        if (!strlen($name))
            $name = null;

        $this->database = $name;
        return $this;
    }
1249410
protected function loadDatabase()
    {
        $this->hook->trigger(self::HOOK_INIT_DATABASE_BEFORE);

        $database = \Parable\DI\Container::get(\Parable\ORM\Database::class);
        $database->setConfig($this->config->get('parable.database'));

        $this->hook->trigger(self::HOOK_INIT_DATABASE_AFTER);
        return $this;
    }
836890
@Then("^a Mongo dataBase '(.+?)' doesnt contains a table '(.+?)'$")
    public void aMongoDataBaseContainsaTable(String database, String tableName) {
        commonspec.getMongoDBClient().connectToMongoDBDataBase(database);
        Set<String> collectionsNames = commonspec.getMongoDBClient().getMongoDBCollections();
        assertThat(collectionsNames).as("The Mongo dataBase contains the table").doesNotContain(tableName);
    }
789727
public function addDatabase(Database $database)
    {
        if (isset($this->databases[$database->getName()])) {
            throw new DBALException("Database '{$database->getName()}' already exists");
        }

        $this->databases[$database->getName()] = $database;
    }
390545
public function createDatabase($database=null)
    {
        if (!$database) $database = $this->getDatabase();
        $sql = $this->getSchema()->getCreateDatabaseSql($database);
        return $this->query($sql);
    }
12112
public function switchDb($db_name)
    {
        $self = $this;

        return $this->app['mongo'] = $this->app->share(
            function () use ($db_name, $self) {
                return new Db($db_name, $self->client, $self->app);
            }
        );
    }