pythonmongodbpymongomongokit

Geospatial Index using MongoKit


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?


Solution

  • 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,