我的问题是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}"
答案 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']%>