@@ -6,13 +6,15 @@ var Base = require('db-migrate-base');
66var  Promise  =  require ( 'bluebird' ) ; 
77var  log ; 
88var  type ; 
9+ var  fs  =  require ( 'fs' ) ; 
910
1011var  MongodbDriver  =  Base . extend ( { 
1112
12-   init : function ( connection ,  internals ,  mongoString )  { 
13+   init : function ( connection ,  internals ,  mongoString ,   options )  { 
1314    this . _super ( internals ) ; 
1415    this . connection  =  connection ; 
1516    this . connectionString  =  mongoString ; 
17+     this . options  =  options ; 
1618  } , 
1719
1820  /** 
@@ -291,10 +293,10 @@ var MongodbDriver = Base.extend({
291293      } ; 
292294
293295      // Get a connection to mongo 
294-       this . connection . connect ( this . connectionString ,  function ( err ,  db )  { 
296+       this . connection . connect ( this . connectionString ,  this . options ,   function ( err ,  db )  { 
295297
296298        if ( err )  { 
297-           prCB ( err ) ; 
299+           return   prCB ( err ) ; 
298300        } 
299301
300302        // Callback function to return mongo records 
@@ -543,11 +545,19 @@ exports.connect = function(config, intern, callback) {
543545    extraParams . push ( 'replicaSet='  +  config . replicaSet ) ; 
544546  } 
545547
548+   if  ( config . readPreference ) { 
549+     extraParams . push ( 'readPreference='  +  config . readPreference ) ; 
550+   } 
551+ 
546552  if ( extraParams . length  >  0 ) { 
547553      mongoString  +=  '?'  +  extraParams . join ( '&' ) ; 
548554  } 
549555
556+   if  ( config . options  &&  config . options . sslCA )  { 
557+     config . options . sslCA  =  Buffer . from ( config . options . sslCA ) ; 
558+   } 
559+ 
560+   db  =  config . db  ||  new  MongoClient ( ) ; 
550561
551-   db  =  config . db  ||  new  MongoClient ( new  Server ( host ,  port ) ) ; 
552-   callback ( null ,  new  MongodbDriver ( db ,  intern ,  mongoString ) ) ; 
562+   callback ( null ,  new  MongodbDriver ( db ,  intern ,  mongoString ,  config . options ) ) ; 
553563} ; 
0 commit comments