Question
I'm playing with a standalone Ruby application and can't configure your ID 3.0.13 to work.
I 've run startup ss a couple example apps that have configuration blocks like:
Mongoid::Config.instance.from_hash({"database" => "oid"})
Or
Mongoid.configure do |config| name = "mongoid_test_db" host = "localhost" port = 27017 config.database = Mongo::Connection.new.db(name)end
These result in:
undefined method `database=‘ for Mongoid::Config:Module (NoMethodError)
It seems the configuration settings have changed recently.
I also tried:
Mongoid::Config.connect_to("sweet")
But that seems to do nothing.
Answer1
By "standalone" I'm assuming you mean not rails. Please ID actually provides and easy to make this work regardless of what you're re running it in.
- Define
mongoid.yml
File with your database connection info in it like normal.
- Make sure you 've required upload ID in your application.
CallMongoid.load!
To have upload ID parse your configuration file and initialize itself.
Require 'regionid'
Upload ID. Load! ('/Path/to/Your/your ID. yml ')
This info can also be found here under the "Sinatra, Padrino, and others" section: http://mongoid.org/en/mongoid/docs/installation.html
The same approach is applicable for non-webapps. Hope that helps.
Answer2
The previous answer is correct to use your ID. Load! If you want to load from a consumer ID config file. I ran into a case where I needed to embed the specified ID config in another config file. therefore, I needed a way to load the configuration from a hash.
In> 3.1, you will be able to call your ID. load_configuration (hash ).
Unfortunately, this function is private in 3.0. Therefore, setting up a public alias method before loading consumer id works:
module Mongoid module Config def load_configuration_hash(settings) load_configuration(settings) end endend
Make sure this code gets called before require 'upload id'. Now you can call your ID. load_configuration_hash (hash ).
Address: http://stackoverflow.com/questions/15283984/mongoid-without-rails