@@ -6,13 +6,15 @@ var Base = require('db-migrate-base');
6
6
var Promise = require ( 'bluebird' ) ;
7
7
var log ;
8
8
var type ;
9
+ var fs = require ( 'fs' ) ;
9
10
10
11
var MongodbDriver = Base . extend ( {
11
12
12
- init : function ( connection , internals , mongoString ) {
13
+ init : function ( connection , internals , mongoString , options ) {
13
14
this . _super ( internals ) ;
14
15
this . connection = connection ;
15
16
this . connectionString = mongoString ;
17
+ this . options = options ;
16
18
} ,
17
19
18
20
/**
@@ -291,10 +293,10 @@ var MongodbDriver = Base.extend({
291
293
} ;
292
294
293
295
// 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 ) {
295
297
296
298
if ( err ) {
297
- prCB ( err ) ;
299
+ return prCB ( err ) ;
298
300
}
299
301
300
302
// Callback function to return mongo records
@@ -543,11 +545,19 @@ exports.connect = function(config, intern, callback) {
543
545
extraParams . push ( 'replicaSet=' + config . replicaSet ) ;
544
546
}
545
547
548
+ if ( config . readPreference ) {
549
+ extraParams . push ( 'readPreference=' + config . readPreference ) ;
550
+ }
551
+
546
552
if ( extraParams . length > 0 ) {
547
553
mongoString += '?' + extraParams . join ( '&' ) ;
548
554
}
549
555
556
+ if ( config . options . sslCA ) {
557
+ config . options . sslCA = Buffer . from ( config . options . sslCA ) ;
558
+ }
559
+
560
+ db = config . db || new MongoClient ( ) ;
550
561
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 ) ) ;
553
563
} ;
0 commit comments