【问题标题】:(node:32032) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoError: Authentication failed(节点:32032)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝 id:1):MongoError:身份验证失败
【发布时间】:2019-02-24 07:24:16
【问题描述】:

我正在尝试从 mlabs 连接 mongodb。我插入了以下代码:

Mongoose.connect('mongodb://<dhan004>:<password1>@ds163402.mlab.com:63402/projecttwist', {useNewUrlParser: true }); 

然后它给了我这个错误:

(node:32032) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoError: Authentication failed.

谁能解释我为什么会收到这个错误?

【问题讨论】:

  • 该错误表明它验证失败,因此请检查连接字符串的用户名和密码部分,通常为:protocol://username:password@host:port/path,在这种情况下协议为mongodbhost:port您也应该仔细检查的部分,在这种情况下,path 部分指向数据库。在此基础上仔细检查所有部分,然后重试。
  • 感谢您的帮助。谢谢!

标签: node.js mongodb mongoose cloud9


【解决方案1】:

只需从用户名和密码部分删除括号()。

用户名应使用:dhan004

对于您应该使用的密码:password1

所以你的最终数据库地址应该是:

Mongoose.connect('mongodb://dhan004:password1@ds163402.mlab.com:63402/projecttwist', {useNewUrlParser: true });

【讨论】:

  • 很高兴为您提供帮助。请您将接受的标志添加到答案中。
猜你喜欢
  • 1970-01-01
  • 2019-04-16
  • 1970-01-01
  • 2018-12-20
  • 1970-01-01
  • 1970-01-01
  • 2018-01-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多