MongoMapper will only use the file if you use Rails and the file is in config/mongo.yml. If you are not using Rails, you can configure this code from the source :
config_file = Rails.root.join('config/mongo.yml')
if config_file.file?
config = YAML.load(ERB.new(config_file.read).result)
MongoMapper.setup(config, Rails.env, :logger => Rails.logger)
end
In addition, the โadapterโ in your file is extraneous. (See Getting Started Documentation ). A mongo.ymlof is rails g mongo_mapper:configas follows:
defaults: &defaults
host: 127.0.0.1
port: 27017
development:
<<: *defaults
database: my_app_development
test:
<<: *defaults
database: my_app_test
production:
<<: *defaults
database: my_app
username: <%= ENV['MONGO_USERNAME'] %>
password: <%= ENV['MONGO_PASSWORD'] %>
source
share