Domanda

I've been searching for this for so many hours. Everytime I call the 'near' method on my Model, it gives the following error:

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 } }"

I've already tried running: rake db:mongoid:create_indexes

Using Ruby 2, Rails 4, Mongoid 4, MongoDB 2.4.4 and Geocoder 1.1.8. And BTW I'm using Mongoid-Paranoia Gem too. I've also tried pointing all gems to their github repos with no luck. I've opened an issue here as well.

Any help appreciated.

È stato utile?

Soluzione

With countless hours of debugging, I've found that installing the Geocoder Gem from HEAD actually fixed the problem, as the Gem's Author said:

gem 'geocoder', github: 'alexreisner/geocoder'

But at the time it didn't work for me. I think my database was corrupted. I say that because I had to completely remove all DBs from my Local Machine and also Remove & Add the MongoHQ addon again to my Heroku instance as well, just to make it work (since the problem persisted on Heroku as well).

Once I did that, I just re-did rake db:mongoid:create_indexes and everything was working perfectly.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top