【问题标题】:Rails Mongoid fails to authenticate - failed with error 13: "not authorized for query on my_db.my_collection"Rails Mongoid 无法验证 - 失败并出现错误 13:“未授权查询 my_db.my_collection”
【发布时间】:2015-07-04 17:33:07
【问题描述】:

This issue 据说可以解决最新版本的助力车,但仍然发生在我身上。 我有一个带有 Mongoid 的 rails 4.2 应用程序,为具有 readWritedbOwner 角色的 MongoDB DB 创建了一个用户,并设置了 auth=truemong.conf 文件中。
我可以使用 Mongo shell 或使用 Mongo 驱动程序的简单 Java 应用程序使用该用户凭据在数据库上执行任何操作。
但是,当尝试使用 Mongoid 进行身份验证时,我总是收到此错误:

因错误 13 失败:“未授权查询 my_db.my_collection”

这是我的 mongoid.yml 文件的相关部分:

production:
  # Configure available database sessions. (required)
  sessions:
    # Defines the default session. (required)
    default:
      # Defines the name of the default database that Mongoid can connect to.
      # (required).
      database: my_db
      hosts:
              - localhost:27017
      username: my_username
      password: my_password

我也尝试用服务器的远程地址替换主机并远程访问它(在禁用身份验证选项的情况下),但没有成功。 对于它的价值,我可以通过调试 mpped/node.rb 文件来查看凭据,在 ensure_connected 方法中我看到 @credentials 变量包含我的用户名和密码 我在这里想念什么? 谢谢!

【问题讨论】:

  • 谢谢,但正如我所说,我也使用了 readWrite 角色,它适用于其他客户端。这不是正确的答案
  • 如果您升级用户输入dbOwner 是否还会出现错误?
  • @Orr :您找到解决问题的方法了吗?
  • @Drakes 实际上用户已经拥有 dbOwner 和 readWrite 权限,而不是我第一次说的 dbAdmin 和 readWrite 权限,所以这并没有解决它......

标签: ruby-on-rails mongodb mongoid moped nosql


【解决方案1】:

也遇到了这个问题。我愿意猜测您正在运行 MongoDB 3+?

坏消息: Moped 2(今天被 mongoid 使用)不支持 MongoDB 3+ 的身份验证。

Moped 在支持服务器 3.0 版的许多基本功能方面也存在不足。例如,它根本不支持使用 MongoDB 3.0 或最新版本的有线协议进行身份验证(包括 listCollections、listIndexes 等命令以及批量写入的能力)。将 Mongoid 与 Ruby 驱动程序 2.0 集成将为 ODM 带来很多这种功能和前向兼容性。 Source

好消息: 目前正在进行重大的重写(Mongoid 5),这将得到 MongoDB 团队的支持。您今天可以从 master 中提取并测试它...但我不建议用于生产,因为它非常不稳定。

解决方案选项

  1. 从 MongoDB 和任何公共 DNS 中删除用户/传递身份验证到数据库。使用带有私钥的 SSH 并连接到私有地址。
  2. 降级到 MongoDB 2.x
  3. 使用 Mongoid 5

【讨论】:

猜你喜欢
  • 2021-09-07
  • 1970-01-01
  • 2018-12-26
  • 1970-01-01
  • 2018-01-30
  • 2014-12-28
  • 1970-01-01
  • 2014-10-12
  • 2013-07-29
相关资源
最近更新 更多