From 6353b52023cf50f1f5ada6c018d021c33ed540ba Mon Sep 17 00:00:00 2001 From: Adrien Joly <531781+adrienjoly@users.noreply.github.com> Date: Sun, 27 Oct 2019 13:00:20 +0100 Subject: [PATCH] fix(db): fix db auth problem in production (#240) intends to fix the following error message in production: ``` === Sun, 27 Oct 2019 11:38:50 GMT, Warning (concise trace) at Object.exports.init (/home/adrien/openwhyd/app/models/mongodb.js:163:23) the options [useUnifiedTopology] is not supported /home/adrien/openwhyd/node_modules/mongodb/lib/mongo_client.js:462 throw err ^ MongoError: Authentication failed. at Function.MongoError.create (/home/adrien/openwhyd/node_modules/mongodb-core/lib/error.js:31:11) at /home/adrien/openwhyd/node_modules/mongodb-core/lib/connection/pool.js:497:72 at authenticateStragglers (/home/adrien/openwhyd/node_modules/mongodb-core/lib/connection/pool.js:443:16) at Connection.messageHandler (/home/adrien/openwhyd/node_modules/mongodb-core/lib/connection/pool.js:477:5) at Socket. (/home/adrien/openwhyd/node_modules/mongodb-core/lib/connection/connection.js:333:22) at Socket.emit (events.js:198:13) ``` --- app/models/mongodb.js | 4 ++-- scripts/algolia-search-index/mongodb-wrapper.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/mongodb.js b/app/models/mongodb.js index f8893b7ad..2a956f12e 100644 --- a/app/models/mongodb.js +++ b/app/models/mongodb.js @@ -144,9 +144,9 @@ exports.init = function(readyCallback) { var authStr = ''; if (authUser && authPassword) authStr = authUser + ':' + authPassword + '@'; - var url = 'mongodb://' + authStr + host + ':' + port; // + "?w=1"; + var url = 'mongodb://' + authStr + host + ':' + port + '/' + dbName; // + "?w=1"; - console.log('Connecting to ' + url + '/' + dbName + '...'); + console.log('Connecting to ' + url + '...'); var options = { native_parser: true, diff --git a/scripts/algolia-search-index/mongodb-wrapper.js b/scripts/algolia-search-index/mongodb-wrapper.js index 9bd43c6e1..dc575740e 100644 --- a/scripts/algolia-search-index/mongodb-wrapper.js +++ b/scripts/algolia-search-index/mongodb-wrapper.js @@ -41,9 +41,9 @@ const cacheCollections = function(db, callback) { }; const initMongo = (params, callback) => { - var url = makeConnUrl(params); + var url = makeConnUrl(params) + '/' + dbName; var dbName = params.mongoDbDatabase || process.env.MONGODB_DATABASE; - console.log('Connecting to ' + url + '/' + dbName + '...'); + console.log('Connecting to ' + url + '...'); mongodb.MongoClient.connect(url, MONGO_OPTIONS, (err, client) => { if (err) { callback(err);