Created
September 7, 2012 23:16
-
-
Save angelsystem/3670617 to your computer and use it in GitHub Desktop.
Rails and MongoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To use multiple MongoDB database through Mongoid use set_database inside the Mongoid model to set the database | |
module Cache | |
class Inquiry | |
include Mongoid::Document | |
set_database :cache | |
... | |
And add the configuration for :cache to mongoid.yml | |
production: | |
database: abc_production | |
hosts: [[server1, 27017], [server2, 27017]] | |
databases: | |
cache: | |
database: cache_production | |
hosts: [[server3, 27017], [server4, 27017]] | |
To use namespacing, which we use for all our Mongoid Models, add the :class_name at the end of any references in the Mongoid model, for example: | |
module Cache | |
class Owner | |
include Mongoid::Document | |
embeds_one :inquiry, :class_name => 'Cache::Inquiry' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment