File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ public function __construct(array $config)
4141 $ this ->connection = $ this ->createConnection ($ dsn , $ config , $ options );
4242
4343 // Select database
44- $ this ->db = $ this ->connection ->selectDatabase ($ config [ ' database ' ] );
44+ $ this ->db = $ this ->connection ->selectDatabase ($ this -> getDatabaseDsn ( $ dsn ) );
4545
4646 $ this ->useDefaultPostProcessor ();
4747
@@ -191,10 +191,19 @@ protected function getHostDsn(array $config)
191191
192192 // Check if we want to authenticate against a specific database.
193193 $ auth_database = isset ($ config ['options ' ]) && !empty ($ config ['options ' ]['database ' ]) ? $ config ['options ' ]['database ' ] : null ;
194-
195194 return 'mongodb:// ' . implode (', ' , $ hosts ) . ($ auth_database ? '/ ' . $ auth_database : '' );
196195 }
197196
197+ /**
198+ * Get database name from DSN string.
199+ * @param string $dsn
200+ * @return string
201+ */
202+ protected function getDatabaseDsn ($ dsn )
203+ {
204+ return trim (parse_url ($ dsn , PHP_URL_PATH ), '/ ' );
205+ }
206+
198207 /**
199208 * Create a DSN string from a configuration.
200209 *
You can’t perform that action at this time.
0 commit comments