Skip to content

Commit

Permalink
fix: adds topology discovery for sharded cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Reggi committed Oct 13, 2020
1 parent efd906a commit f8fd310
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
9 changes: 0 additions & 9 deletions lib/core/uri_parser.js
Expand Up @@ -687,15 +687,6 @@ 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
16 changes: 16 additions & 0 deletions test/functional/sharding_connection.test.js
@@ -1,13 +1,29 @@
'use strict';

const withClient = require('./shared').withClient;
const setupDatabase = require('./shared').setupDatabase;
const expect = require('chai').expect;
const TopologyType = require('../../lib/core/sdam/common').TopologyType;

describe('Sharding (Connection)', function() {
before(function() {
return setupDatabase(this.configuration);
});

it('Should use sharded topology', {
metadata: { requires: { topology: 'sharded' } },
test: function() {
const client = this.configuration.newClient({}, { useUnifiedTopology: true });
return withClient(client, (client, done) => {
expect(client).to.exist;
expect(client)
.nested.property('topology.description.type')
.to.equal(TopologyType.Sharded);
return done();
})();
}
});

/**
* @ignore
*/
Expand Down

0 comments on commit f8fd310

Please sign in to comment.