我已经找了这么多小时了。每次我在我的模型上调用'near‘方法时,它都会给出以下错误:
2.0.0p247 :001 > Status.near(@coordinates, 10).to_a
Moped::Errors::QueryFailure: The operation: #<Moped::Protocol::Query
@length=157
@request_id=3
@response_to=0
@op_code=2004
@flags=[:slave_ok]
@full_collection_name="howsmycity_development.statuses"
@skip=0
@limit=0
@selector={"deleted_at"=>nil, "coordinates"=>{"$nearSphere"=>[74.3344609, 31.5130751], "$maxDistance"=>0.002526046147566618}}
@fields=nil>
failed with error 13038: "can't find any special indices: 2d (needs index), 2dsphere (needs index), for: { deleted_at: null, coordinates: { $nearSphere: [ 74.3344609, 31.5130751 ], $maxDistance: 0.002526046147566618 } }"我已经试过运行:rake db:mongoid:create_indexes
使用Ruby2、Rails 4、Mongoid4、MongoDB 2.4.4和Geo编码器1.1.8。我也在用蒙古-偏执狂宝石。我也尝试过将所有宝石指向他们的github repos,而没有运气。我还开了一期这里。
任何帮助都很感激。
发布于 2013-08-11 03:46:50
经过无数小时的调试,我发现从HEAD安装Geocoder实际上解决了这个问题,就像创业板作者说一样
gem 'geocoder', github: 'alexreisner/geocoder',但当时它对我不起作用。,我想我的数据库被破坏了。我这样说是因为我必须从本地机器上完全删除所有DB,并且还必须删除&将MongoHQ插件再次添加到我的 Heroku 实例中,这只是为了使它正常工作(因为这个问题在Heroku上也一直存在)。
一旦我这么做了,我就重新做了rake db:mongoid:create_indexes,一切都很完美。
https://stackoverflow.com/questions/18134764
复制相似问题