0

Is there a way to create geospatial indexes over fields in a MongoKit Document?

Right now I can't find any reference to do so using the indexes descriptor.

I would like to have something like

class Foo(Document):
    structure = {
        'location': {
            'lat': float,
            'lon': float
        }
    }
    indexes = [
        {
            'fields': ['location'],
            'type': '2d'
        }
    ]

Can I do this using Pymongo?

sebasmagri
  • 170
  • 2
  • 10

1 Answers1

0

It was documented.

To create a geospatial index you need to:

class Foo(Document):
    structure = {
        'location': {
            'lat': float,
            'lon': float
        }
    }
    indexes = [
        {
            'fields': [('location', '2d'), ],
        }
    ]

I had to look at the sources to realize this.

Regards,

sebasmagri
  • 170
  • 2
  • 10
  • 2
    `If you use latitude and longitude as your coordinate system, always store longitude first. MongoDB’s 2d spherical index operators only recognize [ longitude, latitude] ordering.` excerpt from here - http://docs.mongodb.org/manual/core/geospatial-indexes/#store-location-data – zetdotpi Mar 19 '13 at 02:01