问题
Is it possible to use MongoMapper in application that stores its models in many databases? For example I have separated database for Users and another one for Orders and I want to model both User and Order using MongoMapper. Of course I can switch MongoMapper.connection attribute but it is potentially unsafe due to race condition.
回答1:
You can set the connection per model:
User.connection(Mongo::Connection.new('localhost', 27017))
来源:https://stackoverflow.com/questions/6751568/mongomapper-and-more-than-one-databases-in-application