Skip to content

Commit

Permalink
fix(db): fix db auth problem in production (#240)
Browse files Browse the repository at this point in the history
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.<anonymous> (/home/adrien/openwhyd/node_modules/mongodb-core/lib/connection/connection.js:333:22)
    at Socket.emit (events.js:198:13)
```
  • Loading branch information
adrienjoly committed Oct 27, 2019
1 parent 37df41e commit 6353b52
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/models/mongodb.js
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions scripts/algolia-search-index/mongodb-wrapper.js
Expand Up @@ -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);
Expand Down

0 comments on commit 6353b52

Please sign in to comment.