heroku mongohq and mongoid Mongo::ConnectionFailure

早过忘川 提交于 2019-11-28 18:52:24
Jacques Crocker

Mongoid (master) now has a URI option in mongoid.yml. So you could do:

production:
  uri: <%= ENV['MONGOHQ_URL'] %>

To use mongoid master in your project, set this in your Gemfile

gem "mongoid", :git => "git@github.com:mongoid/mongoid.git"

Hopefully a new gem will be released soon which will clean things up.

It seems to me that specifying host in the defaults hash overrides the value in uri. To fix it just remove the host from the default, here is my config/mongo.yml:

defaults: &defaults
  allow_dynamic_fields: true
  parameterize_keys: true
  persist_in_safe_mode: true
  raise_not_found_error: true
  reconnect_time: 3
  use_object_ids: true

production:
  <<: *defaults
  uri: <%= ENV['MONGOHQ_URL'] %>

Here is the snippet from mongoid's config.rb:

  mongo_uri = settings["uri"].present? ? URI.parse(settings["uri"]) : OpenStruct.new

  name = settings["database"] || mongo_uri.path.to_s.sub("/", "")
  host = settings["host"] || mongo_uri.host || "localhost" # <= look here
  port = settings["port"] || mongo_uri.port || 27017
Ben

We have some mongoid docs on our heroku section of our docs. They haven't been released officially yet but you can get it to it already. Don't expect much in the way of styles and content yet, but it does have some info that you might find useful for mongoid.

https://devcenter.heroku.com/articles/mongohq

Just a note that this works for me without any issues, as advertised on http://mongoid.github.com/docs/installation/

Gemfile:

gem "rails", '3.0.0.beta3'
gem "mongoid", "2.0.0.beta4"
gem "bson_ext", "0.20.1"

mongoid.yml:

host: xxx.mongohq.com
port: xxx
database: db
username: user
password: xxx
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!