当我以以下方式启动Rails控制台时:
$ 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.
我的config / 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
在生产中:还从作业/文件夹中移出了一些脚本。 当时行得通。 有人可以启发我吗?
我认为您的ENV ['MONGO_URL']包含不正确的内容。 尝试在生产中使用您的开发数据库:
production:
sessions:
default:
database: tgmd
hosts:
- localhost:27017
如果可行。 检查您的ENV ['MONGO_URL']