Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-3767): dont remove db name when auth source provided #3056

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down
14 changes: 14 additions & 0 deletions test/unit/mongo_client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
});