Skip to content

Commit

Permalink
Merge pull request #3091 from Icehunter/master
Browse files Browse the repository at this point in the history
use replicaset if configured
  • Loading branch information
barisusakli committed Apr 28, 2015
2 parents 2286d11 + 6f66209 commit 3b93182
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/database/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,16 @@
nconf.set('mongo:database', '0');
}

var connString = 'mongodb://' + usernamePassword + nconf.get('mongo:host') + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database');
var hosts = nconf.get('mongo:host').split(',');
var ports = nconf.get('mongo:port').toString().split(',');
var servers = [];

for (var i = 0; i < hosts.length; i++) {
servers.push(hosts[i] + ':' + ports[i]);
}

var connString = 'mongodb://' + usernamePassword + servers.join() + '/' + nconf.get('mongo:database');

var connOptions = {
server: {
poolSize: parseInt(nconf.get('mongo:poolSize'), 10) || 10
Expand Down Expand Up @@ -152,4 +161,3 @@
};

}(exports));

8 changes: 8 additions & 0 deletions tests/mocks/databasemock.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
' "password": "",' + '\n' +
' "database": "1"' + '\n' +
'}\n'+
' or (mongo) in a replicaset' + '\n' +
'"test_database": {' + '\n' +
' "host": "127.0.0.1,127.0.0.1,127.0.0.1",' + '\n' +
' "port": "27017,27018,27019",' + '\n' +
' "username": "",' + '\n' +
' "password": "",' + '\n' +
' "database": "nodebb_test"' + '\n' +
'}\n'+
'==========================================================='
);
winston.error(errorText);
Expand Down

0 comments on commit 3b93182

Please sign in to comment.