From 7803fd94520811489fdbd7ecc001c8e6b931d5a1 Mon Sep 17 00:00:00 2001 From: Maha Benzekri Date: Mon, 6 Jan 2025 15:53:43 +0100 Subject: [PATCH] fixup post reviews --- .../configManager/MongoConfigManager.js | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/extensions/notification/configManager/MongoConfigManager.js b/extensions/notification/configManager/MongoConfigManager.js index f66710006..1ea5c5d46 100644 --- a/extensions/notification/configManager/MongoConfigManager.js +++ b/extensions/notification/configManager/MongoConfigManager.js @@ -7,6 +7,7 @@ const LRUCache = require('arsenal').algorithms const { errors } = require('arsenal'); const MongoClient = require('mongodb').MongoClient; +const { promisify } = require('util'); const ChangeStream = require('../../../lib/wrappers/ChangeStream'); const { constructConnectionString, getMongoVersion } = require('../../utils/MongoUtils'); @@ -89,11 +90,11 @@ class MongoConfigManager extends BaseConfigManager { this._metastoreChangeStream = null; } - /** + /** * Connects to MongoDB using the MongoClientInterface * and retrieves the metastore collection. * @param {Function} cb - Callback function that takes an optional error argument. - * @returns {Promise} - A promise that resolves when the connection is established. + * @returns {undefined} - This method does not return a value. */ async _setupMongoClient(cb) { const mongoUrl = constructConnectionString(this._mongoConfig); @@ -106,23 +107,12 @@ class MongoConfigManager extends BaseConfigManager { this._logger.debug('Connected to MongoDB', { method: 'MongoConfigManager._setupMongoClient', }); - this._mongoClient = client.db(this._mongoConfig.database, { ignoreUndefined: true, }); this._metastore = this._mongoClient.collection(this._bucketMetastore); - - getMongoVersion(this._mongoClient, (err, version) => { - if (err) { - this._logger.error('Could not get MongoDB version', { - method: 'MongoConfigManager._setupMongoClient', - error: err.message, - }); - return cb(err); - } - this._mongoVersion = version; - return cb(); - }); + this._mongoVersion = await promisify(getMongoVersion)(this._mongoClient); + return cb(); } catch (err) { this._logger.error('Could not connect to MongoDB', { method: 'MongoConfigManager._setupMongoClient', @@ -130,7 +120,6 @@ class MongoConfigManager extends BaseConfigManager { }); return cb(err); } - return undefined; } /**