mongo wrapper auth compliant

This commit is contained in:
Erik 2022-04-22 16:51:09 +03:00
parent fe61f9c93f
commit 9adb6db6d1
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -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) {