Mongoid:使用多个数据库?
我在rails应用程序中使用MongoDB和MongoID,某些模型如何成为同一服务器上不同mongo数据库的一部分? 我怎么能做到这样的事情? 我以前遇到过与mysql相同的问题,无法找到合理的解决方案。
有什么想法吗?
最新版本的Mongoid支持这一点。 查看文档 。
摘录:
配置/ mongoid.yml:
defaults: &defaults host: localhost slaves: - host: localhost port: 27018 - host: localhost port: 27019 databases: secondary: database: secondary_database host: localhost port: 27020 slaves: - host: localhost port: 27021 - host: localhost port: 27022
在你的模型中:
class Business include Mongoid::Document set_database :secondary end