我希望能够访问 mongodb://admin:password@db:27017/testdb
,但我一直在访问
Command: ./node_modules/east/bin/east migrate --adapter east-mongo --url mongodb://admin:password@db/testdb
[conn7] SCRAM-SHA-1 authentication failed for admin on testdb from client 172.17.2.60 ; UserNotFound Could not find user admin@testdb
db
是主机名。这就是我所做的:
mongod --storageEngine wiredTiger --httpinterface --rest --master --auth &
mongo admin --eval "db.createUser({user: 'admin', pwd: 'password', roles:[{role:'root',db:'admin'}]});"
如果我这样做
mongo admin -u admin -p password --host db --port 27017
然后 show dbs
工作。
现在我想访问我还没有创建的testdb
,但是根据我的理解,不存在的数据库是动态创建的?
mongo testdb -u admin -p password --host localhost --port 27017
2016-06-08T16:14:02.146+0200 E QUERY Error: 18 Authentication failed.
问题
谁能看出我为什么无法连接?
最佳答案
您正在尝试针对不存在或为空的数据库进行身份验证。这就是身份验证失败的原因。
我愿意
- 登录 MongoDB。
- 执行
use testdb
切换到testdb数据库 - 使用适当的选项执行
db.createuser(...)
以创建可用于身份验证的用户/密码
那么你应该能够按照你描述的去做。
关于node.js - 为什么 MongoDB 中出现 UserNotFound 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37705352/