【发布时间】:2016-09-07 02:40:31
【问题描述】:
我有一个空的环回应用程序, 我在其中添加了一个模型和一个 mongodb 数据源。
连接时出现以下错误:
Web server listening at: http://0.0.0.0:3000
Browse your REST API at http://0.0.0.0:3000/explorer
Connection fails: { [MongoError: Authentication failed.]
name: 'MongoError',
message: 'Authentication failed.',
ok: 0,
code: 18,
errmsg: 'Authentication failed.' }
It will be retried for the next request.
/media/[...]/node_modules/mongodb/lib/mongo_client.js:454
throw err
^
MongoError: Authentication failed.
at Function.MongoError.create (/media/[...]/node_modules/mongodb-core/lib/error.js:31:11)
at /media/[...]/node_modules/mongodb-core/lib/topologies/server.js:778:66
at Callbacks.emit (/media/[...]/node_modules/mongodb-core/lib/topologies/server.js:95:3)
at null.messageHandler (/media/[...]/node_modules/mongodb-core/lib/topologies/server.js:249:23)
at Socket.<anonymous> (/media/[...]/node_modules/mongodb-core/lib/connection/connection.js:265:22)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:153:18)
at Socket.Readable.push (_stream_readable.js:111:10)
at TCP.onread (net.js:531:20)
数据库在 docker 中运行。我可以通过“MongoClient”连接到它
datasources.js:
{
"mongodb_dev": {
"name": "mongodb_dev",
"connector": "mongodb",
"host": "127.0.0.1",
"database": "some-db",
"username": "mongouser",
"password": "pass",
"port": 27017
}
}
【问题讨论】:
-
您确定这些凭据吗?
-
另外,这个问题是在服务器启动时立即发生,还是在您使用 REST API 之后发生?
-
在服务器启动时。是的,我确定 - 这就是为什么我写了我可以通过 MongoClient 连接,所以这也不是端口问题。
-
您是否有执行数据库的
autoupdate或automigrate的启动脚本?如果是的话,可以发一下吗? -
为了消除错误,转到 datasources.json 并将用户名和密码更新为空字符串,然后尝试连接。我有同样的问题,试图找出根本原因。
标签: mongodb loopbackjs