Error Message: MongoError: bad auth Authentication

2020-06-30 07:01发布

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!

9条回答
劫难
2楼-- · 2020-06-30 07:32

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.

查看更多
Rolldiameter
3楼-- · 2020-06-30 07:34
mongodb+srv://jehat123:<password>@jehatarmancdeniz-x2yf7.mongodb.net/question-answer?retryWrites=true&w=majority

Delete all of password part

Use like this:

mongodb+srv://jehat123:yourpass@jehatarmancdeniz-x2yf7.mongodb.net/question-answer?retryWrites=true&w=majority
查看更多
放我归山
4楼-- · 2020-06-30 07:41

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 been my_login_id:my_password.

查看更多
登录 后发表回答