From 3256a5d65d706b113ddfbfab70e647f8df20d8ac Mon Sep 17 00:00:00 2001 From: Michael Schmatz Date: Mon, 3 Feb 2014 08:56:32 -0800 Subject: [PATCH] Added support for replica set --- server/routes/db.coffee | 20 ++++++++++++-------- server_config.js | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/server/routes/db.coffee b/server/routes/db.coffee index 195a0d92c..02798e6af 100644 --- a/server/routes/db.coffee +++ b/server/routes/db.coffee @@ -39,14 +39,18 @@ schemas = module.exports.connectDatabase = () -> - dbName = config.mongo.db - dbName += '_unittest' if testing - address = config.mongo.host + ":" + config.mongo.port - if config.mongo.username and config.mongo.password - address = config.mongo.username + ":" + config.mongo.password + "@" + address -# address = config.mongo.username + "@" + address # if connecting to production server - address = "mongodb://#{address}/#{dbName}" - console.log "got address:", address + if config.mongo.mongoose_replica_string + address = config.mongo.mongoose_replica_string + winston.info "Connecting to replica set: #{address}" + else + dbName = config.mongo.db + dbName += '_unittest' if testing + address = config.mongo.host + ":" + config.mongo.port + if config.mongo.username and config.mongo.password + address = config.mongo.username + ":" + config.mongo.password + "@" + address + # address = config.mongo.username + "@" + address # if connecting to production server + address = "mongodb://#{address}/#{dbName}" + winston.info "Connecting to standalone server #{address}" mongoose.connect address mongoose.connection.once 'open', -> Grid.gfs = Grid(mongoose.connection.db, mongoose.mongo) diff --git a/server_config.js b/server_config.js index 98b642994..67140215e 100644 --- a/server_config.js +++ b/server_config.js @@ -10,6 +10,7 @@ config.mongo = {}; config.mongo.port = process.env.COCO_MONGO_PORT || 27017; config.mongo.host = process.env.COCO_MONGO_HOST || 'localhost'; config.mongo.db = process.env.COCO_MONGO_DATABASE_NAME || 'coco'; +config.mongo.mongoose_replica_string = process.env.COCO_MONGO_MONGOOSE_REPLICA_STRING || ''; if(config.unittest) { config.port += 1;