Skip to content

Commit

Permalink
fixup post mongo bump
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Nov 28, 2024
1 parent b41f3f9 commit 3bf4e46
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
27 changes: 15 additions & 12 deletions lib/storage/metadata/mongoclient/LogConsumer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'; // eslint-disable-line

const MongoClient = require('mongodb').MongoClient;
const { MongoClient } = require('mongodb');
const ListRecordStream = require('./ListRecordStream');
const MongoUtils = require('./utils');

Expand All @@ -16,10 +16,11 @@ class LogConsumer {
* @param {string} logger - logger
*/
constructor(mongoConfig, logger) {
const { authCredentials, replicaSetHosts, replicaSet, database } = mongoConfig;
const { authCredentials, replicaSetHosts, replicaSet, database, readPreference } = mongoConfig;
const cred = MongoUtils.credPrefix(authCredentials);
this._mongoUrl = `mongodb://${cred}${replicaSetHosts}/`;
this._replicaSet = replicaSet;
this._readPreference = readPreference;
this._logger = logger;
this._oplogNsRegExp = new RegExp(`^${database}\\.`);
// oplog collection
Expand All @@ -35,27 +36,29 @@ class LogConsumer {
* @return {undefined}
*/
connectMongo(done) {
MongoClient.connect(this._mongoUrl, {
const client = new MongoClient(this._mongoUrl, {
replicaSet: this._replicaSet,
useNewUrlParser: true,
},
(err, client) => {
if (err) {
this._logger.error('Unable to connect to MongoDB',
{ error: err });
return done(err);
}
useUnifiedTopology: true,
readPreference: this._readPreference,
});

client.connect().then(client => {
this._logger.info('connected to mongodb');
// 'local' is the database where MongoDB has oplog.rs
// capped collection
// 'local' is the database where MongoDB has oplog.rs capped collection
const db = client.db('local', {
ignoreUndefined: true,
});
this._coll = db.collection('oplog.rs');
return done();
})
.catch(err => {
this._logger.error('Unable to connect to MongoDB', { error: err });
return done(err);
});
}


/**
* Open a tailable cursor to mongo oplog and retrieve a stream of
* records to read
Expand Down
6 changes: 4 additions & 2 deletions lib/storage/metadata/mongoclient/MongoClientInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const BucketInfo = require('../../../models/BucketInfo').default;
const ObjectMD = require('../../../models/ObjectMD').default;
const jsutil = require('../../../jsutil');

const MongoClient = require('mongodb').MongoClient;
const { MongoClient } = require('mongodb');
const Uuid = require('uuid');
const diskusage = require('diskusage');

Expand Down Expand Up @@ -148,7 +148,9 @@ class MongoClientInterface {
!Number.isNaN(process.env.MONGO_POOL_SIZE)) {
options.poolSize = Number.parseInt(process.env.MONGO_POOL_SIZE, 10);
}
return MongoClient.connect(this.mongoUrl, options)
const client = new MongoClient(this.mongoUrl, options);

return client.connect()
.then(client => {
this.logger.info('connected to mongodb');
this.client = client;
Expand Down

0 comments on commit 3bf4e46

Please sign in to comment.