2015-04-26 53 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

相關問題