Skip to content

fix: adds topology discovery for mongos #2557

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

Merged
merged 6 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 0 additions & 9 deletions lib/core/uri_parser.js
Original file line number Diff line number Diff line change
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
17 changes: 17 additions & 0 deletions test/functional/sharding_connection.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
'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 });
expect(client.s.options).to.have.property('useUnifiedTopology', true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer not to observe private properties, I think it's satisfactory to have the check for the topology description type below.

return withClient(client, (client, done) => {
expect(client).to.exist;
expect(client.topology).to.exist;
expect(client.topology.description).to.exist;
expect(client.topology.description).to.have.property('type', TopologyType.Sharded);
return done();
})();
}
});

/**
* @ignore
*/
Expand Down