Added support for replica set

This commit is contained in:
Michael Schmatz 2014-02-03 08:56:32 -08:00
parent e920054695
commit 3256a5d65d
2 changed files with 13 additions and 8 deletions

View file

@ -39,14 +39,18 @@ schemas =
module.exports.connectDatabase = () -> module.exports.connectDatabase = () ->
dbName = config.mongo.db if config.mongo.mongoose_replica_string
dbName += '_unittest' if testing address = config.mongo.mongoose_replica_string
address = config.mongo.host + ":" + config.mongo.port winston.info "Connecting to replica set: #{address}"
if config.mongo.username and config.mongo.password else
address = config.mongo.username + ":" + config.mongo.password + "@" + address dbName = config.mongo.db
# address = config.mongo.username + "@" + address # if connecting to production server dbName += '_unittest' if testing
address = "mongodb://#{address}/#{dbName}" address = config.mongo.host + ":" + config.mongo.port
console.log "got address:", address 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.connect address
mongoose.connection.once 'open', -> mongoose.connection.once 'open', ->
Grid.gfs = Grid(mongoose.connection.db, mongoose.mongo) Grid.gfs = Grid(mongoose.connection.db, mongoose.mongo)

View file

@ -10,6 +10,7 @@ config.mongo = {};
config.mongo.port = process.env.COCO_MONGO_PORT || 27017; config.mongo.port = process.env.COCO_MONGO_PORT || 27017;
config.mongo.host = process.env.COCO_MONGO_HOST || 'localhost'; config.mongo.host = process.env.COCO_MONGO_HOST || 'localhost';
config.mongo.db = process.env.COCO_MONGO_DATABASE_NAME || 'coco'; 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) { if(config.unittest) {
config.port += 1; config.port += 1;