forked from Galactic/galactic-bot
mongo wrapper auth compliant
This commit is contained in:
parent
fe61f9c93f
commit
9adb6db6d1
@ -10,12 +10,17 @@ class MongoDBProvider extends Provider {
|
|||||||
config
|
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() {
|
async initialize() {
|
||||||
|
|
||||||
try {
|
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);
|
this.db = await this.connection.db(this.config.database);
|
||||||
return this._initialized = true; //eslint-disable-line no-return-assign
|
return this._initialized = true; //eslint-disable-line no-return-assign
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user