Very new to MongoDB and Node.js. I'm trying to connect to my mongoDB server via the connection string given to me by mongo:
"mongodb+srv://david:password@cluster0-re3gq.mongodb.net/test?retryWrites=true"
In my code I am calling the connection through mongoose like this (obviously putting in my password):
const mongoose = require('mongoose');
const db = 'mongodb+srv://david:<password>@cluster0-re3gq.mongodb.net/test?retryWrites=true'
mongoose
.connect(db, {
useNewUrlParser: true,
useCreateIndex: true
})
.then(() => console.log('MongoDB connected...'))
.catch(err => console.log(err));
When I run the code I am getting the following error
"MongoError: bad auth Authentication failed."
Any ideas of what that could mean? Thanks!
I think you're confused with the mongodb account password and user password. You should use user password, not account password. That was the reason of my case.
Delete all of password part
Use like this:
I had the same problem, and in my case, the answer was as simple as removing the angle brackets "<"and ">" around
<password>
. I had been trying:my_login_id:<my_password>
, when it should have beenmy_login_id:my_password
.