我的Rails应用程序有自己的MySQL数据库(并且需要mysql2gem),但是还需要连接某个特定模型的外部MongoDB数据库(因此我在Gemfile中包含了mongoid和bson_ext).现在,当我try 为新模型生成迁移时,它告诉我
$ rails g migration CreateLocations
error mongoid [not found]
当我生成位置模型时,它包含了Mongoid::Document,所以Rails显然认为它使用外部数据库作为我的主要数据存储.
数据库.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