Skip to content

Commit

Permalink
changed mongoose connect IBM#19
Browse files Browse the repository at this point in the history
  • Loading branch information
faizalak committed Sep 29, 2021
1 parent 48704ac commit d5e80d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion accounts/.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
PORT=3400
MONGO_URL='mongodb://user:[email protected]/admin'
MONGODB_REPLICA_HOSTNAMES: example-mongodb-svc.mongodb.svc.cluster.local:27017
MONGODB_DBNAME: example
MONGODB_DBNAME: admin
MONGODB_USER: user
MONGODB_PASSWORD: password
MONGODB_AUTH_DBNAME: admin
MONGODB_REPLICA_SET: example-node-deployment
MONGODB_CA_PATH: ''
BASE_PATH=0.0.0.0
13 changes: 12 additions & 1 deletion accounts/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,27 @@ require('dotenv').config({silent: true, path: `${__dirname}/.env`});
var server = require('./app');
var port = 3400;

console.log(`Running on ${process.env.BASE_PATH}:${port}, connecting to ${process.env.MONGO_URL}`)
// environment variables for mongodb connection
const MONGODB_REPLICA_HOSTNAMES = process.env.MONGODB_REPLICA_HOSTNAMES
const MONGODB_REPLICA_SET = process.env.MONGODB_REPLICA_SET
const MONGODB_DBNAME = process.env.MONGODB_DBNAME
const MONGODB_AUTH_DBNAME = process.env.MONGODB_AUTH_DBNAME || MONGODB_DBNAME
const MONGODB_CA_PATH = process.env.MONGODB_CA_PATH
const MONGODB_USER = process.env.MONGODB_USER
const MONGODB_PASSWORD = process.env.MONGODB_PASSWORD

console.log(`Running on ${process.env.BASE_PATH}:${port}, connecting to ${process.env.MONGO_URL} and mongo host `+MONGODB_REPLICA_HOSTNAMES)

// connection to mongodb
mongoose
.connect('mongodb://' + MONGODB_REPLICA_HOSTNAMES + '/', {
user: MONGODB_USER,
pass: MONGODB_PASSWORD,
dbName: MONGODB_DBNAME,
replicaSet: MONGODB_REPLICA_SET,
authSource: MONGODB_AUTH_DBNAME,
tls: false,
tlsCAFile: MONGODB_CA_PATH,
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true})
Expand Down

0 comments on commit d5e80d5

Please sign in to comment.