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)
41
41
$ this ->connection = $ this ->createConnection ($ dsn , $ config , $ options );
42
42
43
43
// Select database
44
- $ this ->db = $ this ->connection ->selectDatabase ($ config [ ' database ' ] );
44
+ $ this ->db = $ this ->connection ->selectDatabase ($ this -> getDatabaseDsn ( $ dsn ) );
45
45
46
46
$ this ->useDefaultPostProcessor ();
47
47
@@ -191,10 +191,19 @@ protected function getHostDsn(array $config)
191
191
192
192
// Check if we want to authenticate against a specific database.
193
193
$ auth_database = isset ($ config ['options ' ]) && !empty ($ config ['options ' ]['database ' ]) ? $ config ['options ' ]['database ' ] : null ;
194
-
195
194
return 'mongodb:// ' . implode (', ' , $ hosts ) . ($ auth_database ? '/ ' . $ auth_database : '' );
196
195
}
197
196
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
+
198
207
/**
199
208
* Create a DSN string from a configuration.
200
209
*
You can’t perform that action at this time.
0 commit comments