Skip to content

Commit

Permalink
fixup post reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Jan 6, 2025
1 parent 43148e0 commit 7803fd9
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions extensions/notification/configManager/MongoConfigManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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<void>} - 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);
Expand All @@ -106,31 +107,19 @@ 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',
error: err.message,
});
return cb(err);
}
return undefined;
}

/**
Expand Down

0 comments on commit 7803fd9

Please sign in to comment.