Skip to content
This repository has been archived by the owner on Sep 29, 2022. It is now read-only.

Commit

Permalink
🎨 Refactor init function after mongoose upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
acollierr17 committed Dec 25, 2021
1 parent 29fe7e7 commit 2d49ddc
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/providers/mongodb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,15 @@ module.exports = class MongoDB {
}

async init() {
const dbOptions = {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
await mongoose.connect(process.env.MONGO_URI, {
autoIndex: false,
poolSize: 5,
connectTimeoutMS: 10000,
family: 4
};
}, err => {
if (err) Logger.error('MONGODB ERROR', err);
return true;
});

const prodOptions = {
...dbOptions,
ssl: true,
sslValidate: true,
sslCA: process.env.MONGO_CERTIFICATE
};

const connected = await mongoose.connect(process.env.MONGO_URI, this.client.production ? prodOptions : dbOptions)
.catch(err => Logger.error('MONGODB ERROR', err));

this.Promise = global.Promise;
this.connection = connected.connection;
this.connection = mongoose.connection;
}
};

0 comments on commit 2d49ddc

Please sign in to comment.