ruby on rails - what is the equivalent of ActiveRecord#establish_connection in Mongoid? -


The table is a mucyd model that should rotate in different databases / tables

  # App / Models / Tables Monoged in the RB category table: Document end # App / Controllers / some_controller.Rb DIF index includes table.connection.database =: other_database # & lt; - How to do it ??? Table.table_name = params [: id] # & lt; - How to do it ??? @records = table.all end  

I want the table range:

  1. The configured per-request is separate database (same mongodeb On the server connection)

Edit
I know about:

  • Former> Mongeide Configuring | Config | Name = "control_development" host = "localhost" config.master = Mongo :: connection.new.db (name) config.slaves = [Mongo :: connection.new (host, 27018 ,: slave_ok => true). DB (name)] config.persist_in_safe_mode = false end

    But does it work for some models (?):

      # like this I mean Class User Mongoid :: Document Configure | Config | Include # Configure the connection name of this model only = "other_control_evolution" host = "localhost" config.master = Mongo :: connection.new.db (name) config.slaves = [Mongo :: connection.new (host , 27018 ,: slave_ok = & gt; true) .db (name)] config.persist_in_safe_mode = false end end  
  • You can connect to multiple databases using it.

    Sample configuration:

    In your model:

      set_database: secondary  

    By the way you want, you can not swap the database on it. It's in the list of careers, though keep an eye on this.


    Comments