node.js - 为什么 MongoDB 中出现 UserNotFound 错误?

标签 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 ; 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.

问题

谁能看出我为什么无法连接?

最佳答案

您正在尝试针对不存在或为空的数据库进行身份验证。这就是身份验证失败的原因。

我愿意

  1. 登录 MongoDB。
  2. 执行use testdb切换到testdb数据库
  3. 使用适当的选项执行 db.createuser(...) 以创建可用于身份验证的用户/密码

那么你应该能够按照你描述的去做。

关于node.js - 为什么 MongoDB 中出现 UserNotFound 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37705352/

相关文章:

python - 如何使用python动态地将方法导出到dbus,而不需要静态装饰器?

linux - Unix 逆序多列排序不起作用

regex - grep 和 sed 正则表达式含义 - 从网页中提取 url

bash - Gitlab CI部署AWS EC2

javascript - 我们可以打印/存储 console.time() - console.timeEnd() 的值吗?

javascript - 等待元素出现在页面对象模式上下文中的 TestCafe 中

NodeJS 中的 JavaScript OOP : how?

javascript - 如何以编程方式更新 Node 模块

php - PHP的编译oci8,只停留在检查动态链接器的特性?为什么卡住了?

linux - 使用 PowerShell 脚本中的 WinSCP .NET 程序集在 Linux 服务器上运行 bash 脚本