Skip to content
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

Altered creation of connections to mongo to allow for replications sets to be defined in config.js #74

Merged
merged 1 commit into from
Oct 18, 2013
Merged
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
11 changes: 11 additions & 0 deletions api/config.sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ var countlyConfig = {
port: 27017,
max_pool_size: 1000
},
/* or for a replication set
mongodb: {
replSetServers : [ '192.168.3.1:27017/?auto_reconnect=true',
'192.168.3.2:27017/?auto_reconnect=true' ],
db: "countly",
max_pool_size: 1000
},
*/
/* or define as a url
mongodb: "localhost:27017/countly?auto_reconnect=true"
*/
api: {
workers: 0,
port: 3001,
Expand Down
13 changes: 11 additions & 2 deletions api/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,17 @@ var common = {},
'has_ongoing_session': 'hos'
};

var connectionString = (typeof countlyConfig.mongodb === "string")? countlyConfig.mongodb : (countlyConfig.mongodb.host + ':' + countlyConfig.mongodb.port + '/' + countlyConfig.mongodb.db + '?auto_reconnect=true');
common.db = mongo.db(connectionString, {safe:false, maxPoolSize: countlyConfig.mongodb.max_pool_size || 1000});
var dbName;
var dbOptions = { safe:false, maxPoolSize: countlyConfig.mongodb.max_pool_size || 1000 };
if (typeof countlyConfig.mongodb === "string" ){
dbName = countlyConfig.mongodb;
} else if ( typeof countlyConfig.mongodb.replSetServers === 'object'){
dbName = countlyConfig.mongodb.replSetServers;
dbOptions.database = countlyConfig.mongodb.db || 'countly';
} else {
dbName = (countlyConfig.mongodb.host + ':' + countlyConfig.mongodb.port + '/' + countlyConfig.mongodb.db + '?auto_reconnect=true');
}
common.db = mongo.db(dbName, dbOptions);

common.config = countlyConfig;

Expand Down
16 changes: 13 additions & 3 deletions frontend/express/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ var http = require('http'),
request = require('request'),
countlyMail = require('../../api/parts/mgmt/mail.js'),
countlyStats = require('../../api/parts/data/stats.js'),
countlyConfig = require('./config'),
connectionString = (typeof countlyConfig.mongodb === "string")? countlyConfig.mongodb : (countlyConfig.mongodb.host + ':' + countlyConfig.mongodb.port + '/' + countlyConfig.mongodb.db + '?auto_reconnect=true&safe=true'),
countlyDb = mongo.db(connectionString, {safe:true});
countlyConfig = require('./config');

var dbName;
var dbOptions = { safe:true };
if (typeof countlyConfig.mongodb === "string" ){
dbName = countlyConfig.mongodb;
} else if ( typeof countlyConfig.mongodb.replSetServers === 'object'){
dbName = countlyConfig.mongodb.replSetServers;
dbOptions.database = countlyConfig.mongodb.db || 'countly';
} else {
dbName = (countlyConfig.mongodb.host + ':' + countlyConfig.mongodb.port + '/' + countlyConfig.mongodb.db + '?auto_reconnect=true');
}
var countlyDb = mongo.db(dbName, dbOptions);

function sha1Hash(str, addSalt) {
var salt = (addSalt) ? new Date().getTime() : "";
Expand Down
10 changes: 10 additions & 0 deletions frontend/express/config.sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ var countlyConfig = {
db: "countly",
port: 27017
},
/* or for a replication set
mongodb: {
replSetServers : [ '192.168.3.1:27017/?auto_reconnect=true',
'192.168.3.2:27017/?auto_reconnect=true' ],
db: "countly",
},
*/
/* or define as a url
mongodb: "localhost:27017/countly?auto_reconnect=true"
*/
web: {
port: 6001,
host: "localhost",
Expand Down