Improvements to indexing documentation (#130)

This commit is contained in:
Ross Lawley 2013-04-29 07:38:31 +00:00
parent 6e2d2f33de
commit b0c1ec04b5
3 changed files with 28 additions and 9 deletions

View File

@ -479,6 +479,10 @@ If a dictionary is passed then the following options are available:
:attr:`unique` (Default: False)
Whether the index should be unique.
:attr:`expireAfterSeconds` (Optional)
Allows you to automatically expire data from a collection by setting the
time in seconds to expire the a field.
.. note::
Inheritance adds extra fields indices see: :ref:`document-inheritance`.
@ -512,6 +516,22 @@ point. To create a geospatial index you must prefix the field with the
],
}
Time To Live indexes
--------------------
A special index type that allows you to automatically expire data from a
collection after a given period. See the official
`ttl <http://docs.mongodb.org/manual/tutorial/expire-data/#expire-data-from-collections-by-setting-ttl>`_
documentation for more information. A common usecase might be session data::
class Session(Document):
created = DateTimeField(default=datetime.now)
meta = {
'indexes': [
{'fields': ['created'], 'expireAfterSeconds': 3600}
]
}
Ordering
========
A default ordering can be specified for your

View File

@ -8,6 +8,7 @@ import uuid
import warnings
from operator import itemgetter
import pymongo
import gridfs
from bson import Binary, DBRef, SON, ObjectId
@ -37,7 +38,6 @@ __all__ = ['StringField', 'URLField', 'EmailField', 'IntField', 'LongField',
'SequenceField', 'UUIDField']
RECURSIVE_REFERENCE_CONSTANT = 'self'
@ -1392,7 +1392,7 @@ class GeoPointField(BaseField):
.. versionadded:: 0.4
"""
_geo_index = True
_geo_index = pymongo.GEO2D
def validate(self, value):
"""Make sure that a geo-value is of type (x, y)

View File

@ -231,8 +231,7 @@ class IndexesTest(unittest.TestCase):
location = DictField()
class Place(Document):
current = DictField(
field=EmbeddedDocumentField('EmbeddedLocation'))
current = DictField(field=EmbeddedDocumentField('EmbeddedLocation'))
meta = {
'allow_inheritance': True,
'indexes': [