Connecting to two databases Mongoid

旧时模样 提交于 2019-11-30 02:28:45

hmm well can you do this seem like you messed your yaml file

development:
  sessions:
    default:
      database: db_development
      username: my_username
      password: my_password
      hosts:
        - myserverip:27017
      options:
        consistency: :eventual
    writeable:
      database: db2_development
      username: myusername2
      password  mypassword2
      hosts:
        -  myserverip2:27018
      options:
        consistency: strong

In your model just write this

store_in session: "writeable"

class MyModel
   include Mongoid::Document
   store_in session: "writeable"
   field :name, type: String
   field :age, type: Integer
end

FYI Never tested with password options but i guess it would work

Hope this help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!