Skip to content

Commit 78f6977

Browse files
authoredAug 9, 2018
fix(mongo_client): translate options for connectWithUrl
Fixes NODE-1531
1 parent 36e92f1 commit 78f6977

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed
 

‎lib/operations/mongo_client_ops.js

+22-7
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,31 @@ function connectWithUrl(mongoClient, url, options, connectCallback) {
296296
// Propagate the events to the client
297297
relayEvents(mongoClient, url);
298298

299+
let finalOptions = Object.assign({}, options);
300+
301+
// If we have a readPreference passed in by the db options, convert it from a string
302+
if (typeof options.readPreference === 'string' || typeof options.read_preference === 'string') {
303+
finalOptions.readPreference = new ReadPreference(
304+
options.readPreference || options.read_preference
305+
);
306+
}
307+
299308
// Connect
300309
return url.connect(
301-
options,
302-
connectHandler(mongoClient, options, (err, topology) => {
310+
finalOptions,
311+
connectHandler(mongoClient, finalOptions, (err, topology) => {
303312
if (err) return connectCallback(err, topology);
304-
if (options.user || options.password || options.authMechanism) {
305-
return authenticate(mongoClient, options.user, options.password, options, err => {
306-
if (err) return connectCallback(err, topology);
307-
connectCallback(err, topology);
308-
});
313+
if (finalOptions.user || finalOptions.password || finalOptions.authMechanism) {
314+
return authenticate(
315+
mongoClient,
316+
finalOptions.user,
317+
finalOptions.password,
318+
finalOptions,
319+
err => {
320+
if (err) return connectCallback(err, topology);
321+
connectCallback(err, topology);
322+
}
323+
);
309324
}
310325

311326
connectCallback(err, topology);

0 commit comments

Comments
 (0)
Please sign in to comment.