Install and Set Up Mongoose Issue

Hello Guys,

I am trying to set up mongoose but getting an authentication failed message again and again. I have read all the topics posted earlier for this issue but still not figured out why my code is not working.

const mongoose = require(‘mongoose’);
const mySecret = process.env[‘MONGO_URI’];
mongoose.connect(mySecret, { useNewUrlParser: true, useUnifiedTopology: true });


node v12.16.1
(node:9255) UnhandledPromiseRejectionWarning: MongoServerError: bad auth : Authentication failed.
at Connection.onMessage (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/cmap/connection.js:203:30)
at MessageStream. (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/cmap/connection.js:63:60)
at MessageStream.emit (events.js:314:20)
at processIncomingData (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/cmap/message_stream.js:108:16)
at MessageStream._write (/home/runner/boilerplate-mongomongoose
 npm start

fcc-mongo-mongoose-challenges@0.0.1 start /home/runner/boilerplate-mongomongoose

Help would be really appreciated.

Did you replace the placeholder <password> part of the connection string with your password? Are you sure you are using the correct password?


Yes. I have checked my password many times.

We really can’t say much based on the information you have posted. But the error is usually because you didn’t use the correct password.

Did you remember to remove the <> part from the password? That is just for the placeholder.

Post your connection string and replace the password with something else.

Thank you so much. Now, my code is working correctly. I did not remove the <> part from the password earlier.