Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoid "no geo index :(" error

Steps to reproduce:

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

Have ran rake db:mongoid:create_indexes

Tried calling:

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

And got:

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 :("

Any suggestions?

like image 322
stevenheidel Avatar asked Jul 14 '13 21:07

stevenheidel


1 Answers

Stupid mistake, forgot to do rake db:mongoid:create_indexes with RAILS_ENV=test for RSpec

Complete command

bundle exec rake db:mongoid:create_indexes RAILS_ENV=test
like image 113
stevenheidel Avatar answered Nov 03 '22 01:11

stevenheidel