问题
How can I have one mongo model go to one database and another using another database?
I've been send this link
https://github.com/jnunemaker/mongomapper/blob/master/lib/mongo_mapper/plugins/persistence.rb
and this stackoverflow answer is like my answer
MongoMapper and more than one databases in application
Where in my application do I set the connection for my Models?
回答1:
The source link you posted is what you want. Those methods are all mixed-in to your models, so:
class MyModel
include MongoMapper::Document
connection(Mongo::Connection.new('localhost', 27017))
set_database_name "my_database"
# ...
end
Since it's just a Mongo::Connection, you can use any of its supported options. (source)
来源:https://stackoverflow.com/questions/9531900/setting-up-mongomapper-for-multiple-databases