我的Rails應用程序都有自己的MySql數據庫(和要求mysql2寶石),而且還需要與外部的MongoDB數據庫連接爲一個特定型號(所以我已經包括在Gemfile中mongoid和bson_ext )。現在,當我嘗試生成一個新的模式遷移,它告訴我,設置默認的數據庫連接的Rails
$ rails g migration CreateLocations
error mongoid [not found]
當我創造它包括Mongoid ::文檔的位置模式,讓Rails的顯然認爲它是使用外部數據庫作爲我的主數據存儲。
databse.yml:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: associalize_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
mongoid.yml:
development:
host: pearl.mongohq.com
port: 27019
username: asfasdf
password: sadfasdf
database: app4574678
test:
host: pearl.mongohq.com
port: 27019
username: asdfadhasdfa
password: hadsadfas
database: app4574678
production:
host: pearl.mongohq.com
port: 27019
username: asdfdfsasda
password: afdasdfdasdf
database: app4574678
UPDATE 型號使用蒙戈
class ExternalMongoModel
include Mongoid::Document
field :title
field :long_title
field :deal_type
field :merchandise_type
field :market_id
field :market_name
field :market_location, type: Array
field :featureType
field :country_code
field :subtitle
field :offer_ends_at
field :price
field :value
field :merchant_type
field :content
field :merchant
index(
[[:division_latlon, Mongo::GEO2D]], background: true
)
end
一種解決方法是在我的Gemfile中註釋掉'mongoid',創建並運行遷移,然後取消註釋並重新綁定。顯然不合法。 – Chris
請發佈使用MongoDB的相關型號代碼。 –
@DeanBrundage更新 – Chris