1

当我启动我的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

在生产中:还从作业/文件夹中移出一些脚本。那时它奏效了。任何人都可以启发我吗?

4

1 回答 1

0

我认为您的 ENV['MONGO_URL'] 包含不正确的内容。尝试在生产中使用您的开发数据库:

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

如果它工作。检查您的 ENV['MONGO_URL']

于 2013-01-08T11:20:16.000 回答