add support for geo indexing - see pymongo.GEO2D

This commit is contained in:
Mike Dirolf 2010-03-11 13:57:27 -05:00
parent 01350e38ad
commit 679aedc01c
4 changed files with 18 additions and 7 deletions

View File

@ -7,3 +7,4 @@
.. autodata:: pymongo.ASCENDING
.. autodata:: pymongo.DESCENDING
.. autodata:: pymongo.GEO2D

View File

@ -21,6 +21,16 @@ ASCENDING = 1
DESCENDING = -1
"""Descending sort order."""
GEO2D = "2d"
"""Index specifier for a 2-dimensional `geospatial index`_.
.. versionadded:: 1.5+
.. note:: Geo-spatial indexing requires server version **>= 1.3.3+**.
.. _geospatial index: http://www.mongodb.org/display/DOCS/Geospatial+Indexing
"""
OFF = 0
"""No database profiling."""
SLOW_ONLY = 1

View File

@ -515,8 +515,8 @@ class Collection(object):
Takes either a single key or a list of (key, direction) pairs.
The key(s) must be an instance of :class:`basestring`, and the
directions must be one of (:data:`~pymongo.ASCENDING`,
:data:`~pymongo.DESCENDING`). Returns the name of the created
index.
:data:`~pymongo.DESCENDING`, :data:`~pymongo.GEO2D`). Returns
the name of the created index.
To create a single key index on the key ``'mike'`` we just use
a string argument:
@ -572,8 +572,8 @@ class Collection(object):
Takes either a single key or a list of (key, direction) pairs.
The key(s) must be an instance of :class:`basestring`, and the
direction(s) must be one of (:data:`~pymongo.ASCENDING`,
:data:`~pymongo.DESCENDING`). See :meth:`create_index` for a
detailed example.
:data:`~pymongo.DESCENDING`, :data:`~pymongo.GEO2D`). See
:meth:`create_index` for a detailed example.
Unlike :meth:`create_index`, which attempts to create an index
unconditionally, :meth:`ensure_index` takes advantage of some

View File

@ -65,9 +65,9 @@ def _index_document(index_list):
for (key, value) in index_list:
if not isinstance(key, basestring):
raise TypeError("first item in each key pair must be a string")
if not isinstance(value, int):
raise TypeError("second item in each key pair must be ASCENDING or "
"DESCENDING")
if value not in [pymongo.ASCENDING, pymongo.DESCENDING, pymongo.GEO2D]:
raise TypeError("second item in each key pair must be ASCENDING, "
"DESCENDING, or GEO2D")
index[key] = value
return index