Node.js 为什么在MongoDB中找不到UserNotFound错误?

Node.js 为什么在MongoDB中找不到UserNotFound错误?,node.js,linux,bash,mongodb,Node.js,Linux,Bash,Mongodb,我希望能够访问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 ;

我希望能够访问
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
然后
showdbs
工作

现在我想访问我还没有创建的
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
  • 执行
    使用testdb
    切换到testdb数据库
  • 使用适当的选项执行
    db.createuser(…)
    ,以创建可用于验证的用户/密码
  • 那么你应该能够做到你所描述的