diff --git a/src/client/storage/providers/MongoDBProvider.ts b/src/client/storage/providers/MongoDBProvider.ts index 886c924..3de2d6f 100644 --- a/src/client/storage/providers/MongoDBProvider.ts +++ b/src/client/storage/providers/MongoDBProvider.ts @@ -22,7 +22,7 @@ class MongoDBProvider extends Provider tables: config.tables }); - const { MONGODB_HOST, MONGODB_PORT, MONGODB_USERNAME, MONGODB_PASSWORD, + const { MONGODB_HOST, MONGODB_PORT, MONGODB_USER, MONGODB_PASS, MONGODB_DATABASE, MONGODB_AUTH_SOURCE, MONGODB_URI } = process.env; if ((!MONGODB_HOST || !MONGODB_PORT || !MONGODB_DATABASE) && !MONGODB_URI) throw new Error('Missing host, port and database OR a connection string'); @@ -35,12 +35,13 @@ class MongoDBProvider extends Provider } else { - const auth = MONGODB_USERNAME ? `${MONGODB_USERNAME}:${MONGODB_PASSWORD}@` : ''; + const auth = MONGODB_USER ? `${MONGODB_USER}:${MONGODB_PASS}@` : ''; if (!auth) this.logger.warn('No auth provided'); this.#URI = `mongodb://${auth}${MONGODB_HOST}/${this.#database}?authSource=${MONGODB_AUTH_SOURCE || this.#database}`; } + this.#client = new MongoClient(this.#URI, config.client); this.#client!.on('error', (error: Error) => this.logger.error(`MongoDB error:\n${error.stack || error.message}`)) .on('timeout', () => this.logger.warn('Connection timed out'))