diff --git a/src/connection_string.ts b/src/connection_string.ts index ed897000dca..4fc5d817e0b 100644 --- a/src/connection_string.ts +++ b/src/connection_string.ts @@ -291,11 +291,6 @@ export function parseOptions( } } - if (urlOptions.has('authSource')) { - // If authSource is an explicit key in the urlOptions we need to remove the dbName - urlOptions.delete('dbName'); - } - const objectOptions = new CaseInsensitiveMap( Object.entries(options).filter(([, v]) => v != null) ); diff --git a/test/unit/mongo_client.test.js b/test/unit/mongo_client.test.js index e5ffce996b6..46e71f09697 100644 --- a/test/unit/mongo_client.test.js +++ b/test/unit/mongo_client.test.js @@ -788,3 +788,17 @@ describe('MongoOptions', function () { expect(thrownError).to.have.property('code', 'ENOTFOUND'); }); }); + +describe('MongoClient', function () { + context('when a db is provided in the URI', function () { + const client = new MongoClient('mongodb://127.0.0.1:27017/dbName?authSource=admin'); + + context('when getting the db with no params', function () { + const db = client.db(); + + it('uses the db from the uri', function () { + expect(db.databaseName).to.equal('dbName'); + }); + }); + }); +});