diff --git a/server.js b/server.js index fa723a05..50dcac4e 100644 --- a/server.js +++ b/server.js @@ -616,7 +616,7 @@ function setUpMongoDB() { console.log("Looking for a MongoDB Cluster..."); - if ((!global.config && !process.env["MONGO_1_PORT_27017_TCP_ADDR"] && !process.env["MONGO_SERVICE_HOST"]) || (!global.config && !process.env["MONGO_PORT_27017_TCP_ADDR"] && !process.env["MONGO_SERVICE_HOST"])) { + if ((!global.config && !process.env["MONGO_1_PORT_27017_TCP_ADDR"] && !process.env["KUBERNETES_STATEFUL_MONGO_URL"])) { console.error("INFO : Not running on Docker. Use docker-compose (recommended) from https://github.com/cloudboost/docker"); } @@ -652,19 +652,17 @@ function setUpMongoDB() { } global.config.mongo = []; - if (process.env["MONGO1_SERVICE_HOST"]) { + if (process.env["KUBERNETES_STATEFUL_MONGO_URL"]) { console.log("MongoDB is running on Kubernetes"); - var i = 1; - while (process.env["MONGO" + i + "_SERVICE_HOST"]) { - global.config.mongo.push({ - host: process.env["MONGO" + i + "_SERVICE_HOST"], - port: process.env["MONGO" + i + "_SERVICE_PORT"] - }); - mongoConnectionString += process.env["MONGO" + i + "_SERVICE_HOST"] + ":" + process.env["MONGO" + i + "_SERVICE_PORT"]; - mongoConnectionString += ","; - ++i; - } - + + global.config.mongo = process.env["KUBERNETES_STATEFUL_MONGO_URL"].split(',').map(function(x,i){ + return { + host:x.split(':')[0], + port:x.split(':')[1] + } + }) + + mongoConnectionString += process.env["KUBERNETES_STATEFUL_MONGO_URL"] isReplicaSet = true; } else {