一个rails项目连多个mongo数据库


 一个rails项目如何连多个mongo数据库呢,答案在这里http://stackoverflow.com/questions/16400458/connecting-to-two-databases-mongoid


(1)首先在config/mongoid.yml里配置一下

development:
  sessions:
    default:
      database: ott_tv_cms_development
      hosts:
        - localhost:27017
      options:
    live:
      database: ott_tv_live_cms_development
      hosts:
        - localhost:27017
      options:

  options:

(2)在对应的model里增加链接信息

class LiveChannel
  include Mongoid::Document
  include Timestamps

  store_in session: "live", collection: 'live_channel'

  field :logo, type: String
  field :name, type: String
  field :channel, type: String

  has_many :live_videos, primary_key: 'channel', foreign_key: 'channel'
end

这样就可以啦



你可能感兴趣的:(一个rails项目连多个mongo数据库)