heroku push Mongo :: ConnectionFailure:无法连接到127.0.0.1:27017的主节点

时间:2014-07-23 17:02:58

标签: ruby-on-rails mongodb heroku

我的问题是Mongo::ConnectionFailure: Failed to connect to a master node at 127.0.0.1:27017,当我推动heroku时。

我正在使用mongomapper。

配置:

defaults: &defaults
  host: 127.0.0.1
  port: 27017
  options:
    w: 1
    pool_size: 1
    slave_ok: false
    ssl: false

development:
  <<: *defaults
  database: devname

test:
  <<: *defaults
  database: testname
  w: 0

production:
  <<: *defaults
  database: devname

连接:

MongoMapper.connection = Mongo::Connection.new('localhost', 27017)

MongoMapper.database = "appname-#{Rails.env}"

1 个答案:

答案 0 :(得分:0)

Fixed it by changed connection config to
if ENV["MONGOLAB_URL"]
  uri = URI.parse(ENV["MONGOLAB_URL"])
  MongoMapper.connection = Mongo::Connection.from_uri(ENV["MONGOLAB_URL"])
  MongoMapper.database = uri.path.gsub(/^\//, '')
else
  MongoMapper.connection = Mongo::Connection.new('localhost')
  MongoMapper.database = "dbname"
end

and inside mongo.yml file
production:
 uri: <%= ENV['MONGOLAB_URI']%>