Skip to content

Commit 1d8a84b

Browse files
achrinzanflaig
andcommitted
fix: handle url default db name
Co-authored-by: Nico Flaig <[email protected]> Signed-off-by: Rifa Achrinza <[email protected]>
1 parent 6ce66e4 commit 1d8a84b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/mongodb.js

+9
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@ MongoDB.prototype.connect = function(callback) {
325325
if (callback) callback(err);
326326
}
327327

328+
const urlObj = new URL(self.settings.url);
329+
330+
if ((urlObj.pathname === '' ||
331+
urlObj.pathname.split('/')[1] === '') &&
332+
typeof self.settings.database === 'string') {
333+
urlObj.pathname = self.settings.database;
334+
self.settings.url = urlObj.toString();
335+
}
336+
328337
new mongodb.MongoClient(self.settings.url, validOptions).connect(function(
329338
err,
330339
client,

0 commit comments

Comments
 (0)