I have a multi-domain Rails 4 app where the request.domain
of the http request determines which functionality I expose a given visitor to.
Each domain in my app should be served by its own MongoDB database. E.g. domain1.com is served by db_for_domain_1, etc.
I can read in the MongoDB docs on runtime persistence that
Mongoid.override_database("db_for_#{request.domain}")
enables me to switch database on the fly.
But how do I keep the persistence when I bypass Mongoid and use the mongo Shell method db.collection.insert()? I will still do it from within my application though.
The answer might be in the MongoDB docs on collection access, but I don't understand it. So how do I switch database before/during this operation?:
MyModel.collection.insert({field_1: "Value 1", field_2: "Value 2"})