File tree 1 file changed +13
-2
lines changed
1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ public function __construct(array $config)
38
38
$ this ->connection = $ this ->createConnection ($ dsn , $ config , $ options );
39
39
40
40
// Select database
41
- $ this ->db = $ this ->connection ->selectDatabase ($ config ['database ' ]);
41
+ $ this ->db = $ this ->connection ->selectDatabase ($ this -> getDatabaseDsn ( $ dsn , $ config ['database ' ]) );
42
42
43
43
$ this ->useDefaultPostProcessor ();
44
44
@@ -188,10 +188,21 @@ protected function getHostDsn(array $config)
188
188
189
189
// Check if we want to authenticate against a specific database.
190
190
$ auth_database = isset ($ config ['options ' ]) && !empty ($ config ['options ' ]['database ' ]) ? $ config ['options ' ]['database ' ] : null ;
191
-
192
191
return 'mongodb:// ' . implode (', ' , $ hosts ) . ($ auth_database ? '/ ' . $ auth_database : '' );
193
192
}
194
193
194
+ /**
195
+ * Get database name from DSN string, if there is no database in DSN path - returns back $database argument.
196
+ * @param string $dsn
197
+ * @param $database
198
+ * @return string
199
+ */
200
+ protected function getDatabaseDsn ($ dsn , $ database )
201
+ {
202
+ $ dsnDatabase = trim (parse_url ($ dsn , PHP_URL_PATH ), '/ ' );
203
+ return trim ($ dsnDatabase ) ? $ dsnDatabase : $ database ;
204
+ }
205
+
195
206
/**
196
207
* Create a DSN string from a configuration.
197
208
* @param array $config
You can’t perform that action at this time.
0 commit comments