Skip to content

Commit 4aa0126

Browse files
author
RandomSeeded
committed
fix(connect): fix connect not using server options correctly
Signed-off-by: RandomSeeded <nate@blend.com>
1 parent 1ff0509 commit 4aa0126

File tree

3 files changed

+41
-31
lines changed

3 files changed

+41
-31
lines changed

index.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ var Base = require('db-migrate-base');
66
var Promise = require('bluebird');
77
var log;
88
var type;
9+
var fs = require('fs');
910

1011
var 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.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
};

package-lock.json

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "db-migrate-mongodb",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"description": "mongodb driver for db-migrate",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)