diff --git a/src/structure/storage/providers/Mongodb.js b/src/structure/storage/providers/Mongodb.js index 8a1aafb..bf7f9ce 100644 --- a/src/structure/storage/providers/Mongodb.js +++ b/src/structure/storage/providers/Mongodb.js @@ -10,12 +10,17 @@ class MongoDBProvider extends Provider { config }); + const { MONGODB_HOST, MONGODB_USERNAME, MONGODB_PASSWORD } = process.env; + const { database } = this.config; + const auth = MONGODB_USERNAME ? `${MONGODB_USERNAME}:${MONGODB_PASSWORD}@`:''; + this.URI = `mongodb://${auth}${MONGODB_HOST}/${database}?authSource=${database}`; + } async initialize() { try { - this.connection = await MongoClient.connect(process.env.MONGODB_HOST + this.config.database, { useUnifiedTopology: true }); + this.connection = await MongoClient.connect(this.URI, { useNewUrlParser: true }); this.db = await this.connection.db(this.config.database); return this._initialized = true; //eslint-disable-line no-return-assign } catch (err) {