Skip to content

Commit 07a3117

Browse files
committed
fix: restore auto direct connection behavior
1 parent b657c8c commit 07a3117

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/core/uri_parser.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,15 @@ function parseConnectionString(uri, options, callback) {
687687
return callback(new MongoParseError('directConnection option requires exactly one host'));
688688
}
689689

690+
// NOTE: this behavior will go away in v4.0, we will always auto discover there
691+
if (
692+
parsedOptions.directConnection == null &&
693+
hosts.length === 1 &&
694+
parsedOptions.replicaSet == null
695+
) {
696+
parsedOptions.directConnection = true;
697+
}
698+
690699
const result = {
691700
hosts: hosts,
692701
auth: auth.db || auth.username ? auth : null,

test/functional/sharding_connection.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ describe('Sharding (Connection)', function() {
1313
it('Should use sharded topology', {
1414
metadata: { requires: { topology: 'sharded' } },
1515
test: function() {
16-
const client = this.configuration.newClient({}, { useUnifiedTopology: true });
16+
const client = this.configuration.newClient(
17+
{},
18+
// note: auto-discovery will be the default behavior in 4.0,
19+
// for now we must supply directConnection: false
20+
{ useUnifiedTopology: true, directConnection: false }
21+
);
1722
return withClient(client, (client, done) => {
1823
expect(client).to.exist;
1924
expect(client)

0 commit comments

Comments
 (0)