Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
osoner committed Oct 18, 2013
2 parents 4285d4a + eab986a commit 6a50a29
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
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

0 comments on commit 6a50a29

Please sign in to comment.