5

重现步骤:

class Venue
  field :coordinates, type: Array
  index({coordinates: '2d'}, {min: -180, max: 180})
end

已经运行 rake db:mongoid:create_indexes

尝试调用:

Venue.geo_near([@lat, @long])

并得到:

Moped::Errors::OperationFailure:
   The operation: #<Moped::Protocol::Command
     @length=135
     @request_id=3
     @response_to=0
     @op_code=2004
     @flags=[]
     @full_collection_name="encore_backend_test.$cmd"
     @skip=0
     @limit=-1
     @selector={:geoNear=>"venues", :near=>[43.670906, -79.393331], :query=>{}, :spherical=>true}
     @fields=nil>
   failed with error "no geo index :("

有什么建议么?

4

1 回答 1

14

db:mongoid:create_indexes愚蠢的错误,忘了RAILS_ENV=test为 RSpec做 rake

完成命令

bundle exec rake db:mongoid:create_indexes RAILS_ENV=test
于 2013-07-15T03:33:45.090 回答