新手问题 Rails 如何连接多个 MongoDB 数据库

nicozhang · November 23, 2016 · Last by nicozhang replied at November 23, 2016 · 1356 hits

gem mongoid 首先在 mongoid.yml 文件里添加几行:

default:
     database: china_scope
     hosts:
       - localhost:27017
     options:
       # Change the default write concern. (default = { w: 1 })
       # write:
       #   w: 1
  name_you_set:
     database: db_name
     hosts:
       - localhost:27017

其次在 model 里添加一行: store_in database:"name_you_set" store_in collection: "collection_name"

You need to Sign in before reply, if you don't have an account, please Sign up first.