2015-04-26 32 views
12

This issue据说解决了最新版本的Moped,但仍然发生在我身上。 我有一个Rails 4.2的应用程序与Mongoid,创造了一个MongoDB的DB用户与读写的dbowner的角色,并在mong.conf文件中设置AUTH =真
我可以使用Mongo shell或使用Mongo驱动程序的简单Java应用程序,使用该用户凭据在数据库上执行任何操作。
但是,试图与Mongoid进行身份验证时,我总是得到这个错误:Rails Mongoid未通过身份验证 - 失败,错误13:“未授权查询my_db.my_collection”

failed with error 13: "not authorized for query on 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变量包含我的用户名和密码 我在这里丢失了什么? 谢谢!

+0

http://stackoverflow.com/questions/17376250/ruby-on-rails-mongoid-and-webfaction-not-authorized-for- query-error-16550 –

+0

谢谢,但正如我所说我也使用readWrite角色,它从其他客户端。这不是正确的答案 – Orr

+0

如果您将用户升级为键入[dbOwner](http://docs.mongodb.org/manual/reference/built-in-roles/#dbOwner),错误是否仍然存在? – Drakes

回答

10

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

坏消息:轻便摩托车2(今天由mongoid使用)不支持对MongoDB 3+进行身份验证。

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的团队的支持。你可以从主人今天拉出来并测试它......但我不会推荐用于生产,因为它非常不稳定。

解选项

  1. 删除用户/通AUTH从MongoDB的和任何公开的DNS数据库。使用SSH与私钥并连接到私有地址。
  2. 降级到MongoDB的2.X
  3. 使用Mongoid 5
+1

感谢你们,我升级到mongoid 5,因为现在它可用,与mongo,而不是轻便摩托车仍然相同的错误! –

+0

mongoid 5.0现在支持认证:https://docs.mongodb.org/ecosystem/tutorial/ruby-mongoid-tutorial/ – Orr

相关问题