Setting up mongomapper for multiple databases

岁酱吖の 提交于 2019-12-21 18:35:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!