Skip to content

Commit

Permalink
mongo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rakesh kumar authored and rakesh kumar committed Dec 12, 2022
1 parent 984dd91 commit cecd7d7
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 cecd7d7

Please sign in to comment.