Skip to content

Commit

Permalink
fix: restore auto direct connection behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
emadum committed Jan 27, 2021
1 parent b657c8c commit 07a3117
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/core/uri_parser.js
Expand Up @@ -687,6 +687,15 @@ function parseConnectionString(uri, options, callback) {
return callback(new MongoParseError('directConnection option requires exactly one host'));
}

// NOTE: this behavior will go away in v4.0, we will always auto discover there
if (
parsedOptions.directConnection == null &&
hosts.length === 1 &&
parsedOptions.replicaSet == null
) {
parsedOptions.directConnection = true;
}

const result = {
hosts: hosts,
auth: auth.db || auth.username ? auth : null,
Expand Down
7 changes: 6 additions & 1 deletion test/functional/sharding_connection.test.js
Expand Up @@ -13,7 +13,12 @@ describe('Sharding (Connection)', function() {
it('Should use sharded topology', {
metadata: { requires: { topology: 'sharded' } },
test: function() {
const client = this.configuration.newClient({}, { useUnifiedTopology: true });
const client = this.configuration.newClient(
{},
// note: auto-discovery will be the default behavior in 4.0,
// for now we must supply directConnection: false
{ useUnifiedTopology: true, directConnection: false }
);
return withClient(client, (client, done) => {
expect(client).to.exist;
expect(client)
Expand Down

0 comments on commit 07a3117

Please sign in to comment.