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"

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

问题描述

这个问题据说已经解决了最新版本的Moped,但仍然发生在我身上. 我有一个 Mongoid 的Rails 4.2应用程序,使用 readWrite 为MongoDB数据库创建了一个用户>和 dbOwner 角色,然后在 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+.

助力车还缺乏支持服务器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团队的支持.您可以今天从大师那里拿出来进行测试...但是由于它非常不稳定,因此我不建议用于生产.

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天全站免登陆