Sokil\Mongo\Client::getDatabase PHP Method

getDatabase() public method

Get database instance
public getDatabase ( string $name = null ) : Database
$name string database name
return Database
    public function getDatabase($name = null)
    {
        if (!$name) {
            $name = $this->getCurrentDatabaseName();
        }
        if (!isset($this->databasePool[$name])) {
            // init db
            $database = new Database($this, $name);
            if (isset($this->mapping[$name])) {
                $database->map($this->mapping[$name]);
            }
            // configure db
            $this->databasePool[$name] = $database;
        }
        return $this->databasePool[$name];
    }

Usage Example

 public function setUp()
 {
     // connect to mongo
     $client = new Client(getenv('PHPMONGO_DSN') ? getenv('PHPMONGO_DSN') : null);
     // select database
     $database = $client->getDatabase('test');
     // select collection
     $this->collection = $database->getCollection('phpmongo_test_collection');
 }
All Usage Examples Of Sokil\Mongo\Client::getDatabase