2013-01-08 35 views
1

當我開始我的Rails控制檯爲:Mongoid只在開發中工作。拋出的錯誤都被測試和生產

$ RAILS_ENV=development rails console 

每一件事情似乎是工作的罰款。 Mongoid能夠連接到mongodb並獲取記錄。

但隨着:

$ RAILS_ENV=test rails console 
$ RAILS_ENV=production rails console 

它扔了錯誤爲:

Rack::File headers parameter replaces cache_control after Rack 1.5. 
/usr/local/lib/ruby/gems/1.9.1/gems/mongoid-3.0.16/lib/mongoid/criteria.rb:585:in `check_for_missing_documents!': (Mongoid::Errors::DocumentNotFound) 
Problem: 
    Document(s) not found for class Actor with id(s) 50e5259f53c205d815000001. 
Summary: 
    When calling Actor.find with an id or array of ids, each parameter must match a document in the database or this error will be raised. The search was for the id(s): 50e5259f53c205d815000001 ... (1 total) and the following ids were not found: 50e5259f53c205d815000001. 
Resolution: 
    Search for an id that is in the database or set the Mongoid.raise_not_found_error configuration option to false, which will cause a nil to be returned instead of raising this error when searching for a single id, or only the matched documents when searching for multiples. 

我的配置/ mongoid.yml具有完全相同的一組對所有三種環境系。 我無法弄清楚爲什麼它無法連接到測試和生產中。

更新: Mongoid.yml

development: 
    sessions: 
    default: 
     database: tgmd 
     hosts: 
     - localhost:27017 
test: 
    sessions: 
    default: 
     database: tgmd 
     hosts: 
     - localhost:27017 
production: 
    sessions: 
    default: 
     uri: <%= ENV['MONGO_URL'] %> 

我暫時放置一個解決該問題:

options: 
    raise_not_found_error: false 

生產: 也從以往的工作/文件夾移出幾個腳本。當時它工作。 任何人都可以在這方面啓發我嗎?

+0

你可以發佈你的「config/mongoid.yml」+ Gemfile。並嘗試創建你的數據庫。 「rake db:drop rake db:create」 – bulleric

+0

@bulleric:請檢查更新 – Bornfree

+0

也許我錯過了一些東西,但doens't錯誤說你正在嘗試獲取不在數據庫中的文檔?這不是配置問題imo。 – soulcheck

回答

0

我想你的ENV ['MONGO_URL']包含的東西是不正確的。 嘗試在生產中使用您的開發數據庫:

production: 
    sessions: 
    default: 
     database: tgmd 
     hosts: 
     - localhost:27017 

如果有效。檢查你的ENV ['MONGO_URL']

相關問題