@@ -296,16 +296,31 @@ function connectWithUrl(mongoClient, url, options, connectCallback) {
296
296
// Propagate the events to the client
297
297
relayEvents ( mongoClient , url ) ;
298
298
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
+
299
308
// Connect
300
309
return url . connect (
301
- options ,
302
- connectHandler ( mongoClient , options , ( err , topology ) => {
310
+ finalOptions ,
311
+ connectHandler ( mongoClient , finalOptions , ( err , topology ) => {
303
312
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
+ ) ;
309
324
}
310
325
311
326
connectCallback ( err , topology ) ;
0 commit comments