2

I tried to connect MongoDB through mLab.com. It got redirected to MongoDB Atlas. I created one project and cluster. When trying to connect I get the Bad Authentication error, though my credentials are correct.

Password holds special characters. I tried replacing those special characters with ASCII hex code as well, but no response.

I replace my password in the below code

config/keys.js

module.exports = {
  mongoURI: `mongodb+srv://Nikhilesh:<password>@devconnector-gicbg.mongodb.net/test?retryWrites=true`
};

server.js

const mongoose = require("mongoose");
const db = require("./config/keys").mongoURI;

mongoose
  .connect(db, { useNewUrlParser: true })
  .then(() => console.log("DB Connected"))
  .catch(e => console.log(e));

Result:

{ MongoError: bad auth Authentication failed.
    at _authenticateSingleConnection (F:\Web Development\MERN\Projects\DevConnector\node_modules\mongodb-core\lib\auth\auth_provider.js:46:25)
    at sendAuthCommand (F:\Web Development\MERN\Projects\DevConnector\node_modules\mongodb-core\lib\auth\scram.js:214:18)
    at Connection.messageHandler (F:\Web Development\MERN\Projects\DevConnector\node_modules\mongodb-core\lib\connection\connect.js:334:5)
    at Connection.emit (events.js:182:13)
    at processMessage (F:\Web Development\MERN\Projects\DevConnector\node_modules\mongodb-core\lib\connection\connection.js:364:10)
    at TLSSocket.<anonymous> (F:\Web Development\MERN\Projects\DevConnector\node_modules\mongodb-core\lib\connection\connection.js:533:15)
    at TLSSocket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at TLSSocket.Readable.push (_stream_readable.js:219:10)
    at TLSWrap.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
  ok: 0,
  errmsg: 'bad auth Authentication failed.',
  code: 8000,
  codeName: 'AtlasError',
  name: 'MongoError',
  [Symbol(mongoErrorContextSymbol)]: {} }
Nikhilesh A S
  • 169
  • 1
  • 12

1 Answers1

0

Downgrade your mongoose to 5.4.6.

Below mongoose connect set of codes, add

mongoose.Promise = global.Promise;

Let me know if it works.