首页 > 解决方案 > Azure 部署 MongoError:身份验证失败

问题描述

我们如何为 mlab 数据库设置身份验证以连接 azure?我使用 Nodejs 作为堆栈。在我所做的列表下方:

  1. 将 mlab 数据库的 App Setting 设置为 MONGODB_URI,并使用 mongodb://user:password@ds166666.mlab.com:66666/database-name
  2. 在 mlab 数据库上创建管理员用户

这是出现的错误,

MongoError: Authentication failed.
    at Function.MongoError.create (D:\home\site\wwwroot\node_modules\mongodb-core\lib\error.js:31:11)
    at D:\home\site\wwwroot\node_modules\mongodb-core\lib\connection\pool.js:497:72
    at authenticateStragglers (D:\home\site\wwwroot\node_modules\mongodb-core\lib\connection\pool.js:443:16)
    at Connection.messageHandler (D:\home\site\wwwroot\node_modules\mongodb-core\lib\connection\pool.js:477:5)
    at Socket.<anonymous> (D:\home\site\wwwroot\node_modules\mongodb-core\lib\connection\connection.js:331:22)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)

这里的mongo身份验证错误到底是什么?因为我尝试从本地连接到这个远程数据库并且连接没有问题。

谢谢你。

标签: node.jsmongodbazuremlab

解决方案


我使用 azure services 的 cosmosdb 解决了这个问题。似乎默认使用 azure cosmosdb ?ssl=true&replicaSet=globaldb

我认为这就是他们想要的那种授权。不仅仅是db的用户名和密码。


推荐阅读