Rails Mongoid 无法验证 - 失败并出现错误 13:“未授权查询 my_db.my_collection" [英] Rails Mongoid fails to authenticate - failed with error 13: "not authorized for query on my_db.my_collection"

查看:14
本文介绍了Rails Mongoid 无法验证 - 失败并出现错误 13:“未授权查询 my_db.my_collection"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This issue was said to be resolved the latest version of Moped but still happens to me. I have a rails 4.2 app with Mongoid, created a user for a MongoDB DB with readWrite and dbOwner roles, and set auth=true in the mong.conf file.
I can perform any actions on the DB with that user credentials using the Mongo shell or a simple Java application using their Mongo driver.
However, when trying to authenticate with Mongoid I always get this error:

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

failed with error 13: "not authorized for query on my_db.my_collection"

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

Here is the relevant portion of my mongoid.yml file:

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 变量包含我的用户名和密码我在这里想念什么?谢谢!

I've also tried replacing the host with remote address of the server and access it remotely ( which works with the authentication option disabled ) without success. For what's it worth, I can see that the credentials by debugging the mpped/node.rb file, in the ensure_connected method I see that @credentials variable contains my username and password What am I missing here? Thanks!

推荐答案

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

Ran into this problem also. I would be willing to guess you are running MongoDB 3+?

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

The bad news: Moped 2 (which used by mongoid today) does not support authentication for MongoDB 3+.

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

Moped also falls short on a lot of essential functionality for supporting server version 3.0. For example, it simply doesn’t support authentication with MongoDB 3.0 or recent versions of the wire protocol (which includes commands such as listCollections, listIndexes, and the ability to do bulk writes). Integrating Mongoid with Ruby driver 2.0 will bring a lot of this functionality and forward-compatibility to the ODM. Source

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

The good news: A major rewrite is underway right now (Mongoid 5), which will be supported by the MongoDB team. You can pull from master today and test it out...but I would not recommend for production yet as it is highly unstable.

解决方案选项

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

这篇关于Rails Mongoid 无法验证 - 失败并出现错误 13:“未授权查询 my_db.my_collection"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆