Skip to content

Commit cfb7d83

Browse files
committed
fix(client-ops): return transform map to map rather than function
During the refactor of MongoClient operations a mapping variable was mistaken to be a function expression, and we silently broke using the new url parser. This corrects that, renames the mapping variable to make it very clearly that, and adds a test to prove that the new url parser is working again. NODE-1542
1 parent 4af16ad commit cfb7d83

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

lib/operations/mongo_client_ops.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,15 @@ function replayEvents(mongoClient, events) {
508508
}
509509
}
510510

511+
const LEGACY_OPTIONS_MAP = validOptionNames.reduce((obj, name) => {
512+
obj[name.toLowerCase()] = name;
513+
return obj;
514+
}, {});
515+
511516
function transformUrlOptions(_object) {
512517
let object = Object.assign({ servers: _object.hosts }, _object.options);
513518
for (let name in object) {
514-
const camelCaseName = validOptionsLowerCaseToCamelCase[name];
519+
const camelCaseName = LEGACY_OPTIONS_MAP[name];
515520
if (camelCaseName) {
516521
object[camelCaseName] = object[name];
517522
}
@@ -595,11 +600,4 @@ function validOptions(options) {
595600
}
596601
}
597602

598-
function validOptionsLowerCaseToCamelCase() {
599-
validOptionNames.reduce((obj, name) => {
600-
obj[name.toLowerCase()] = name;
601-
return obj;
602-
}, {});
603-
}
604-
605603
module.exports = { connectOp, logout, validOptions };

test/functional/uri_tests.js

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
2-
var expect = require('chai').expect;
2+
3+
const expect = require('chai').expect;
4+
const MongoClient = require('../..').MongoClient;
35

46
describe('URI', function() {
57
/**
@@ -15,7 +17,6 @@ describe('URI', function() {
1517
// The actual test we wish to run
1618
test: function(done) {
1719
var self = this;
18-
var MongoClient = self.configuration.require.MongoClient;
1920

2021
// Connect using the connection string
2122
MongoClient.connect(
@@ -57,7 +58,6 @@ describe('URI', function() {
5758
// The actual test we wish to run
5859
test: function(done) {
5960
var self = this;
60-
var MongoClient = self.configuration.require.MongoClient;
6161

6262
// Connect using the connection string
6363
MongoClient.connect('mongodb://localhost:27017/integration_tests?w=0', function(err, client) {
@@ -89,8 +89,6 @@ describe('URI', function() {
8989

9090
// The actual test we wish to run
9191
test: function(done) {
92-
var MongoClient = this.configuration.require.MongoClient;
93-
9492
if (process.platform !== 'win32') {
9593
MongoClient.connect('mongodb://%2Ftmp%2Fmongodb-27017.sock?safe=false', function(
9694
err,
@@ -114,8 +112,6 @@ describe('URI', function() {
114112
// The actual test we wish to run
115113
test: function(done) {
116114
var self = this;
117-
var MongoClient = self.configuration.require.MongoClient;
118-
119115
MongoClient.connect('mongodb://127.0.0.1:27017/?fsync=true', function(err, client) {
120116
var db = client.db(self.configuration.db);
121117
expect(db.writeConcern.fsync).to.be.true;
@@ -133,7 +129,6 @@ describe('URI', function() {
133129
// The actual test we wish to run
134130
test: function(done) {
135131
var self = this;
136-
var MongoClient = self.configuration.require.MongoClient;
137132

138133
MongoClient.connect(
139134
'mongodb://localhost:27017/integration_tests',
@@ -164,4 +159,22 @@ describe('URI', function() {
164159
);
165160
}
166161
});
162+
163+
it('should correctly translate uri options using new parser', {
164+
metadata: { requires: { topology: 'replicaset' } },
165+
test: function(done) {
166+
const config = this.configuration;
167+
const uri = `mongodb://${config.host}:${config.port}/${config.db}?replicaSet=${
168+
config.replicasetName
169+
}`;
170+
171+
MongoClient.connect(uri, { useNewUrlParser: true }, (err, client) => {
172+
if (err) console.dir(err);
173+
expect(err).to.not.exist;
174+
expect(client).to.exist;
175+
expect(client.s.options.replicaSet).to.exist.and.equal(config.replicasetName);
176+
done();
177+
});
178+
}
179+
});
167180
});

0 commit comments

Comments
 (0)