How to change the current MongoMapper database at runtime?
Also, is there a way of mapping a model to a database whose name is dynamically calculated? For instance:
class MyEntity
include MongoMapper::Document
set_database_name "#{some_dynamic_value}"
end
If you want to use a specific database for a model, do…
You can do do string interpolation there, but that’s only resolved when the class is loaded and then never again.
To calculate a database name every single time a database is needed, override either the class or instance database method.
See the persistence plugin source to get an idea of the kind of damage you can do by overriding.