diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index a999cc6..2b60310 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,3 +1,4 @@ +- Add: db uri and options in mongo connection log INFO trace - Fix: log about getProtocol result - Fix: ensure protocol exists before remove it (#234) - Fix: print URI in logs about redirection error (#232) diff --git a/lib/model/dbConn.js b/lib/model/dbConn.js index b833501..b4b56f1 100644 --- a/lib/model/dbConn.js +++ b/lib/model/dbConn.js @@ -76,10 +76,7 @@ function init(host, db, port, username, password, options, callback) { return previous; } - const hosts = host - .split(',') - .map(addPort) - .reduce(commaConcat, ''); + const hosts = host.split(',').map(addPort).reduce(commaConcat, ''); url = 'mongodb://' + credentials + hosts + '/' + db; @@ -105,46 +102,52 @@ function init(host, db, port, username, password, options, callback) { } function connectionAttempt(url, options, callback) { - logger.info(context, 'Attempting to connect to MongoDB instance. Attempt %d', retries); + logger.info( + context, + 'Attempting to connect to MongoDB instance with url %j and options %j. Attempt %d', + url, + options, + retries + ); // just to avoid warnings with recent mongoose versions options.useNewUrlParser = true; options.useUnifiedTopology = true; mongoose.set('useCreateIndex', true); /* eslint-disable-next-line no-unused-vars */ - const candidateDb = mongoose.createConnection(url, options, function(error, result) { + const candidateDb = mongoose.createConnection(url, options, function (error, result) { if (error) { logger.error(context, 'MONGODB-001: Error trying to connect to MongoDB: %s', error); lastError = error; } else { defaultDb = candidateDb; - defaultDb.on('error', function(error) { + defaultDb.on('error', function (error) { logger.error(context, 'Mongo Driver error: %j', error); }); /* eslint-disable-next-line no-unused-vars */ - defaultDb.on('connecting', function(error) { + defaultDb.on('connecting', function (error) { logger.debug(context, 'Mongo Driver connecting'); }); - defaultDb.on('connected', function() { + defaultDb.on('connected', function () { logger.debug(context, 'Mongo Driver connected'); }); - defaultDb.on('reconnected', function() { + defaultDb.on('reconnected', function () { logger.debug(context, 'Mongo Driver reconnected'); }); - defaultDb.on('disconnected', function() { + defaultDb.on('disconnected', function () { logger.debug(context, 'Mongo Driver disconnected'); }); - defaultDb.on('reconnectFailed', function() { + defaultDb.on('reconnectFailed', function () { logger.error(context, 'MONGODB-004: MongoDB connection was lost'); process.exit(1); }); - defaultDb.on('disconnecting', function() { + defaultDb.on('disconnecting', function () { logger.debug(context, 'Mongo Driver disconnecting'); }); - defaultDb.on('open', function() { + defaultDb.on('open', function () { logger.debug(context, 'Mongo Driver open'); }); - defaultDb.on('close', function() { + defaultDb.on('close', function () { logger.debug(context, 'Mongo Driver close'); }); }