Configure mongomapper for multiple databases

How can I use one mongo model for one database and another using another database?

I sent this link

https://github.com/jnunemaker/mongomapper/blob/master/lib/mongo_mapper/plugins/persistence.rb

and this stackoverflow answer is similar to my answer

MongoMapper and several databases in the application

Where in my application to establish a connection for my models?

+4
source share
1 answer

The original link you submitted is what you want. These methods are mixed with your models, therefore:

class MyModel include MongoMapper::Document connection(Mongo::Connection.new('localhost', 27017)) set_database_name "my_database" # ... end 

Since this is just Mongo :: Connection, you can use any of the supported options . ( source )

+2
source

Source: https://habr.com/ru/post/1399372/


All Articles