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

来源:互联网 发布:淘宝 做工粗糙 有瑕疵 编辑:程序博客网 时间:2024/06/05 06:53


 一个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

这样就可以啦



0 0
原创粉丝点击