2016-08-23 2 views
0

Motorengineはmongodbで非同期db操作を行うための素晴らしいライブラリです。しかし、私はどのように私はmotorengineと地理空間的なクエリを行うことができますかと思います。 ライブラリにはジオフィールドがサポートされていないため、私はモータ2dspearインデックスを使用しているオプションです。しかし、もし私がmotorengineの助けを借りて道を見つけたら本当にいいと思う。motorengineにgeopointプロパティを持つDocumentクラスを作成するには

誰でも私にそれを手伝ってもらえますか?

答えて

0

このような問題は修正されました。

from motorengine.document import Document 
import pymongo 


class BaseDocument(Document): 
     import pymongo 

     ASCENDING = pymongo.ASCENDING 
     DESCENDING = pymongo.DESCENDING 
     GEO2D = pymongo.GEOSPHERE 

     def __init__(self, alias=None, **kwargs): 
      indexes = self.__indexes__ if hasattr(self, "__indexes__") else [] 
      if len(indexes) == 0: 
       return 

      def ensure_index(index, **spec): 
       self.objects.coll(alias).ensure_index(index, **spec) 

      for index_spec in indexes: 
       ensure_index([index_spec]) 

      super(BaseDocument, self).__init__(**kwargs) 

とそのインデックスを使用します。

class Team(BaseDocument): 

    __indexes__ = [('location', BaseDocument.GEO2D)] 

    name = StringField(required=True) 
    location = GeoPointField() 
    contact = StringField(required=True) 
関連する問題