Skip to content

fix(connect): fix connect not using server options correctly #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ var Base = require('db-migrate-base');
var Promise = require('bluebird');
var log;
var type;
var fs = require('fs');

var MongodbDriver = Base.extend({

init: function(connection, internals, mongoString) {
init: function(connection, internals, mongoString, options) {
this._super(internals);
this.connection = connection;
this.connectionString = mongoString;
this.options = options;
},

/**
Expand Down Expand Up @@ -291,10 +293,10 @@ var MongodbDriver = Base.extend({
};

// Get a connection to mongo
this.connection.connect(this.connectionString, function(err, db) {
this.connection.connect(this.connectionString, this.options, function(err, db) {

if(err) {
prCB(err);
return prCB(err);
}

// Callback function to return mongo records
Expand Down Expand Up @@ -543,11 +545,19 @@ exports.connect = function(config, intern, callback) {
extraParams.push('replicaSet=' + config.replicaSet);
}

if (config.readPreference){
extraParams.push('readPreference=' + config.readPreference);
}

if(extraParams.length > 0){
mongoString += '?' + extraParams.join('&');
}

if (config.options && config.options.sslCA) {
config.options.sslCA = Buffer.from(config.options.sslCA);
}

db = config.db || new MongoClient();

db = config.db || new MongoClient(new Server(host, port));
callback(null, new MongodbDriver(db, intern, mongoString));
callback(null, new MongodbDriver(db, intern, mongoString, config.options));
};
50 changes: 25 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "db-migrate-mongodb",
"version": "1.4.0",
"version": "1.5.0",
"description": "mongodb driver for db-migrate",
"main": "index.js",
"scripts": {
Expand Down