我正在尝试跟进该教程,我用lb创建了一个新应用,添加了CoffeeShop模式,然后添加了数据源mongodb。
我的MongoDB实例在我的本地Mac上,并且授权已关闭。
我只是使用mongod
命令运行它,没有多余的参数,也没有其他配置。
这是我的datasources.json
{
"corp1": {
"host": "127.0.0.1",
"port": 27017,
"url": "",
"database": "devdb",
"password": "devpassword",
"name": "corp1",
"user": "devuser",
"connector": "mongodb"
}
}
我什至创建了devdb
数据库,并以admin身份将devdb用户授予所有数据库。
仍然出现此错误。
Connection fails: MongoError: Authentication failed.
It will be retried for the next request.
/Users/hazimdikenli/learn/loopback-getting-started/node_modules/mongodb/lib/mongo_client.js:462
throw err
^
MongoError: Authentication failed.
at Function.MongoError.create (/Users/hazimdikenli/learn/loopback-getting-started/node_modules/mongodb-core/lib/error.js:31:11)
at /Users/hazimdikenli/learn/loopback-getting-started/node_modules/mongodb-core/lib/connection/pool.js:497:72
at authenticateStragglers (/Users/hazimdikenli/learn/loopback-getting-started/node_modules/mongodb-core/lib/connection/pool.js:443:16)
at Connection.messageHandler (/Users/hazimdikenli/learn/loopback-getting-started/node_modules/mongodb-core/lib/connection/pool.js:477:5)
at Socket.<anonymous> (/Users/hazimdikenli/learn/loopback-getting-started/node_modules/mongodb-core/lib/connection/connection.js:333: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)
at TCP.onread (net.js:597:20)
它以为这是新手问题,但我找不到问题。因此,请帮助我解决此问题。
答案 0 :(得分:0)
尽管我没有使用--auth选项运行mongod,但仍然证明它是身份验证问题,但在执行以下命令后仍然有效。
db.createUser({
user : "devuser",
pwd : "devpassword",
roles: [ {role: "dbOwner", db: "devdb"},
{role: "readWrite", db: "devdb"}]
})
在此之前,我使用此脚本授予了“管理员”角色,但看起来还不够。
role: "userAdminAnyDatabase", db: "admin"