Skip to content
This repository was archived by the owner on May 31, 2022. It is now read-only.
Merged
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
11 changes: 11 additions & 0 deletions lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ const getTasks = (model, setupListeners) => {

validOptions.useNewUrlParser = true;
validOptions.useUnifiedTopology = true;
if (
model.directConnection === undefined &&
model.hosts.length === 1 &&
(model.replicaSet === undefined || model.replicaSet === '')
) {
// Previous to the node driver 3.6.3, directConnection was
// set to true under these conditions. In 3.6.3 this defaulting
// behavior was removed and now we add it. COMPASS-4534
// https://github.com/mongodb/node-mongodb-native/commit/f8fd310a11a91db82f1c0ddc57482b8edabc231b
validOptions.directConnection = true;
}

const mongoClient = new MongoClient(model.driverUrlWithSsh, validOptions);

Expand Down
3 changes: 2 additions & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ const CONNECTION_STRING_OPTIONS = {
'pythonLegacy'
],
default: undefined
}
},
directConnection: { type: 'boolean', default: undefined }
};

assign(props, CONNECTION_STRING_OPTIONS);
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"async": "^3.1.0",
"debug": "^4.1.1",
"lodash": "^4.17.15",
"mongodb": "^3.6.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is why you were asking if we should make that a peer dep right? 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup. I can update that in another PR though to keep things simple. (Maybe it'll require a major release?)

"mongodb": "^3.6.3",
"raf": "^3.4.1",
"ssh2": "^0.8.7",
"storage-mixin": "^3.3.4"
Expand Down
1 change: 1 addition & 0 deletions test/connect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('connection model connector', () => {

assert.deepStrictEqual(options, {
connectWithNoPrimary: true,
directConnection: true,
readPreference: 'primary',
useNewUrlParser: true,
useUnifiedTopology: true
Expand Down
33 changes: 33 additions & 0 deletions test/parse-uri-components.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,39 @@ describe('connection model partser should parse URI components such as', () => {
}
);
});

it('defaults directConnection undefined', (done) => {
Connection.from(
'mongodb://localhost:27017',
(error, result) => {
expect(error).to.not.exist;
expect(result.directConnection).to.be.equal(undefined);
done();
}
);
});

it('saves directConnection true', (done) => {
Connection.from(
'mongodb://localhost:27017/?directConnection=true',
(error, result) => {
expect(error).to.not.exist;
expect(result.directConnection).to.be.equal(true);
done();
}
);
});

it('saves directConnection false', (done) => {
Connection.from(
'mongodb://localhost:27017/?directConnection=false',
(error, result) => {
expect(error).to.not.exist;
expect(result.directConnection).to.be.equal(false);
done();
}
);
});
});

describe('miscellaneous configuration', () => {
Expand Down