MongoDB 客户端访问控制 : SCRAM-SHA-1 authentication failed, 存储 key 不匹配

标签 mongodb

我正在尝试在我的本地 Mongo 安装上激活用户授权,但身份验证一直失败。可能是什么问题?我错过了什么吗?

我遵循了“Installing on Windows”和“Enable Client Access Control”中列出的步骤:

1) 添加了一个用户

>mongo admin
MongoDB shell version: 3.2.7
connecting to: admin
> db.createUser({createUser:"admin",pwd:"admin",roles:["root"]})
Successfully added user: { "createUser" : "admin", "roles" : [ "root" ] }
>

2) 在 mongod.cfg 中启用客户端访问控制:

systemLog:
    destination: file
    path: c:\data\log\mongod.log
storage:
    dbPath: c:\data\db
security:
    authorization: enabled

3) 重启mongod

4) 现在使用“正确”凭据(我刚刚指定的凭据)登录总是失败:

>mongo admin -u admin -p admin
MongoDB shell version: 3.2.7
connecting to: admin
2016-06-14T12:25:02.376+0200 E QUERY    [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1441:20
@(auth):6:1
@(auth):1:2

exception: login failed

日志文件中的错误是:来自客户端 127.0.0.1 的 admin 上的 admin 的 SCRAM-SHA-1 身份验证失败; AuthenticationFailed:SCRAM-SHA-1 认证失败,storedKey 不匹配

如果重要的话,平台是 Windows 10 x64。 带有 OpenSSL 的 MongoDB 64 位 3.2.7。

最佳答案

作为per the documentation ,传递给 createUser 的对象应该包含一个 user 属性(以及其他属性):

db.createUser({ user : "admin", pwd : "admin", roles : ["root"] })
                ^^^^ not `createUser`

关于MongoDB 客户端访问控制 : SCRAM-SHA-1 authentication failed, 存储 key 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37811036/

相关文章:

MongoDB 聚合和投影

java - 使用 elem 对子文档数组进行 Morphia 查询

node.js - 如何在mongodb查询中使用变量作为字段值?

python - 如何使用 pymongo 更新值?

node.js - Azure Functions 在 Node 中加载 MongoDB 时发生崩溃

mongodb - mongodb中的成对交叉点

java - 如何以编程方式从文件中的值实例化动态加载的类?

javascript - 使嵌套模式虚拟 Mongoose 的验证无效

java - 如何使用 Mongo Java 驱动程序从集合中检索随机文档

arrays - 如何获取 MongoDB 聚合管道中不在另一个数组中的数组元素?