나는 코디네이트 된 주소와 주소를 저장하는이 모델을 가지고 있습니다. 이 모델은 테스트 용입니다.지오 코더 (geocoder)가 몽고로 울 (roong)과 작동하지 않음
class Geomodel
include Mongoid::Document
include Geocoder::Model::Mongoid
field :coordinates, type: Array
field :address
before_save :update_coordinates
def update_coordinates
self.address = Geocoder.search(self.coordinates).first.address
end
reverse_geocoded_by :coordinates
after_validation :reverse_geocode # auto-fetch address
end
좌표 및 주소를 저장할 수 있습니다. 하지만 사용할 수 없습니다
obj = Geomodel.near (좌표 : [xx, xx]). 아래와 같이 Mongo 기준을 보여줍니다. #Mongoid::Criteria selector: {"coordinates"=>{"$near"=>[xx, xx]}} options: {} class: Geomodel embedded: false>
또한 테스트를 위해 개체를 배열로 변환 할 때이 오류가 표시됩니다. obj.to_a
Moped::Errors::QueryFailure: The operation: #<Moped::Protocol::Query @length=114 @request_id=18 @response_to=0 @op_code=2004 @flags=[] @full_collection_name="staging_development.geomodels" @skip=0 @limit=0 @selector={"coordinates"=>{"$near"=>[73.8719, 18.6139]}} @fields=nil> failed with error 13038: "can't find any special indices: 2d (needs index), 2dsphere (needs index), for: { coordinates: { $near: [ 73.8719, 18.6139 ] } }"
문제를 해결하거나 지오 코더와 쿼리에 대해 알고있는 가장 좋은 튜토리얼에 대한 링크를 제공하는 방법을 도와주세요. RAILS 4 및 MONGOID gem을 사용하고 있습니다.
추신 : 나는이 전체적인 오류가 다음과 같은 이유 때문이라고 생각합니다.
1.Creating 범위 : 가까운. 기존 메서드 Geomodel.near을 덮어 씁니다.
2. 2dsphere 색인 때문일 수 있습니다.