Skip to content

Commit

Permalink
fix(mongo_client): translate options for connectWithUrl
Browse files Browse the repository at this point in the history
Fixes NODE-1531
  • Loading branch information
kvwalker authored Aug 9, 2018
1 parent 36e92f1 commit 78f6977
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions lib/operations/mongo_client_ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,31 @@ function connectWithUrl(mongoClient, url, options, connectCallback) {
// Propagate the events to the client
relayEvents(mongoClient, url);

let finalOptions = Object.assign({}, options);

// If we have a readPreference passed in by the db options, convert it from a string
if (typeof options.readPreference === 'string' || typeof options.read_preference === 'string') {
finalOptions.readPreference = new ReadPreference(
options.readPreference || options.read_preference
);
}

// Connect
return url.connect(
options,
connectHandler(mongoClient, options, (err, topology) => {
finalOptions,
connectHandler(mongoClient, finalOptions, (err, topology) => {
if (err) return connectCallback(err, topology);
if (options.user || options.password || options.authMechanism) {
return authenticate(mongoClient, options.user, options.password, options, err => {
if (err) return connectCallback(err, topology);
connectCallback(err, topology);
});
if (finalOptions.user || finalOptions.password || finalOptions.authMechanism) {
return authenticate(
mongoClient,
finalOptions.user,
finalOptions.password,
finalOptions,
err => {
if (err) return connectCallback(err, topology);
connectCallback(err, topology);
}
);
}

connectCallback(err, topology);
Expand Down

0 comments on commit 78f6977

Please sign in to comment.