我正在尝试通过 mongo 给我的连接字符串连接到我的 mongoDB 服务器:
"mongodb+srv://david:password@cluster0-re3gq.mongodb.net/test?retryWrites=true"
在我的代码中,我像这样通过 mongoose 调用连接(显然输入我的密码):
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));
当我运行代码时出现以下错误
"MongoError: bad auth Authentication failed."
你知道这意味着什么吗?
最佳答案
我遇到了同样的问题,就我而言,答案很简单,就是删除 <password>
周围的尖括号“<”和“>” .我一直在尝试:my_login_id:<my_password>
, 当它应该是 my_login_id:my_password
.
关于node.js - 错误消息 : MongoError: bad auth Authentication failed through URI string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55695565/