Comparing version 1.6.20 to 1.6.21
@@ -47,30 +47,36 @@ 'use strict'; | ||
var server; | ||
var connectionUrl; | ||
if (options.servers && Array.isArray(options.servers)){ | ||
var servers = []; | ||
if (options.url) { | ||
connectionUrl = options.url; | ||
} else { | ||
var members = options.servers | ||
? options.servers | ||
: [{host: options.host, port: options.port}]; | ||
options.servers.forEach(function(item){ | ||
if(item.host && item.port) { | ||
servers.push(new mongo.Server(item.host, item.port, item.options)); | ||
} | ||
}); | ||
var memberString = _(members).map(function(m) { return m.host + ':' + m.port }); | ||
var authString = options.username && options.password | ||
? options.username + ':' + options.password + '@' | ||
: ''; | ||
var optionsString = options.authSource | ||
? '?authSource=' + options.authSource | ||
: ''; | ||
server = new mongo.ReplSet(servers); | ||
} else { | ||
server = new mongo.Server(options.host, options.port, options.options); | ||
connectionUrl = 'mongodb://' + authString + memberString + '/' + options.dbName + optionsString; | ||
} | ||
this.db = new mongo.Db(options.dbName, server, { safe: true }); | ||
this.db.on('close', function() { | ||
self.emit('disconnect'); | ||
self.stopHeartbeat(); | ||
}); | ||
var client = new mongo.MongoClient(); | ||
this.db.open(function (err, client) { | ||
client.connect(connectionUrl, options.options, function(err, db) { | ||
if (err) { | ||
if (callback) callback(err); | ||
} else { | ||
self.db = db; | ||
self.db.on('close', function() { | ||
self.emit('disconnect'); | ||
self.stopHeartbeat(); | ||
}); | ||
var finish = function (err) { | ||
self.client = client; | ||
self.store = self.db.collection(options.collectionName); | ||
@@ -88,10 +94,3 @@ // self.store.ensureIndex({ 'aggregateId': 1, date: 1 }, function() {}); | ||
if (options.authSource && options.username) { | ||
// Authenticate with authSource | ||
client.authenticate(options.username, options.password, {authSource: options.authSource}, finish); | ||
} else if (options.username) { | ||
client.authenticate(options.username, options.password, finish); | ||
} else { | ||
finish(); | ||
} | ||
finish(); | ||
} | ||
@@ -98,0 +97,0 @@ }); |
@@ -47,30 +47,36 @@ 'use strict'; | ||
var server; | ||
var connectionUrl; | ||
if (options.servers && Array.isArray(options.servers)){ | ||
var servers = []; | ||
if (options.url) { | ||
connectionUrl = options.url; | ||
} else { | ||
var members = options.servers | ||
? options.servers | ||
: [{host: options.host, port: options.port}]; | ||
options.servers.forEach(function(item){ | ||
if(item.host && item.port) { | ||
servers.push(new mongo.Server(item.host, item.port, item.options)); | ||
} | ||
}); | ||
var memberString = _(members).map(function(m) { return m.host + ':' + m.port }); | ||
var authString = options.username && options.password | ||
? options.username + ':' + options.password + '@' | ||
: ''; | ||
var optionsString = options.authSource | ||
? '?authSource=' + options.authSource | ||
: ''; | ||
server = new mongo.ReplSet(servers); | ||
} else { | ||
server = new mongo.Server(options.host, options.port, options.options); | ||
connectionUrl = 'mongodb://' + authString + memberString + '/' + options.dbName + optionsString; | ||
} | ||
this.db = new mongo.Db(options.dbName, server, { safe: true }); | ||
this.db.on('close', function() { | ||
self.emit('disconnect'); | ||
self.stopHeartbeat(); | ||
}); | ||
var client = new mongo.MongoClient(); | ||
this.db.open(function (err, client) { | ||
client.connect(connectionUrl, options.options, function(err, db) { | ||
if (err) { | ||
if (callback) callback(err); | ||
} else { | ||
self.db = db; | ||
self.db.on('close', function() { | ||
self.emit('disconnect'); | ||
self.stopHeartbeat(); | ||
}); | ||
var finish = function (err) { | ||
self.client = client; | ||
self.store = self.db.collection(options.collectionName); | ||
@@ -90,10 +96,3 @@ self.store.ensureIndex({ '_commands.id': 1}, function() {}); | ||
if (options.authSource && options.username) { | ||
// Authenticate with authSource | ||
client.authenticate(options.username, options.password, {authSource: options.authSource}, finish); | ||
} else if (options.username) { | ||
client.authenticate(options.username, options.password, finish); | ||
} else { | ||
finish(); | ||
} | ||
finish(); | ||
} | ||
@@ -100,0 +99,0 @@ }); |
{ | ||
"author": "adrai", | ||
"name": "cqrs-saga", | ||
"version": "1.6.20", | ||
"version": "1.6.21", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -41,2 +41,3 @@ # Introduction | ||
// password: 'secret' // optional | ||
// url: 'mongodb://user:pass@host:port/db?opts // optional | ||
}, | ||
@@ -43,0 +44,0 @@ // or redis: |
@@ -0,1 +1,4 @@ | ||
## [v1.6.21](https://github.com/adrai/node-cqrs-saga/compare/v1.6.20...v1.6.21) | ||
- Support mongo connection string | ||
## [v1.6.20](https://github.com/adrai/node-cqrs-saga/compare/v1.6.19...v1.6.20) | ||
@@ -2,0 +5,0 @@ - redis, mongodb: call disconnect on ping error |
556
165923
4478