Skip to content

Commit

Permalink
Merge pull request #89 from ELEVATE-Project/mongofix
Browse files Browse the repository at this point in the history
mongo fix
  • Loading branch information
rakeshSgr authored Dec 12, 2022
2 parents 9ae3955 + cecd7d7 commit 970d285
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/configs/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,17 @@ const mongoose_timestamp = require('mongoose-timestamp')
module.exports = function () {
// Added to remove depreciation warnings from logs.

let parameters
let parameters = ''
if (process.env.REPLICA_SET_NAME) {
parameters = '?replicaSet=' + process.env.REPLICA_SET_NAME
}
if (process.env.REPLICA_SET_NAME && process.env.REPLICA_SET_READ_PREFERENCE) {
parameters = parameters + '&readPreference=' + process.env.REPLICA_SET_READ_PREFERENCE
}

if (parameters) {
const db = mongoose.createConnection(process.env.MONGODB_URL + parameters, {
useNewUrlParser: true,
})
} else {
const db = mongoose.createConnection(process.env.MONGODB_URL, {
useNewUrlParser: true,
})
}
const db = mongoose.createConnection(process.env.MONGODB_URL + parameters, {
useNewUrlParser: true,
})

db.on('error', function () {
console.log('Database connection error:')
Expand Down

0 comments on commit 970d285

Please sign in to comment.