Ensure Indexes before Each Save

- Rely on caching within the PyMongo driver to provide lightweight calls
  while indices are cached.
- Closes MongoEngine/mongoengine#812.
This commit is contained in:
Matthew Ellison
2014-12-03 23:50:51 -05:00
committed by Matthew Ellison
parent ff659a0be3
commit db36d0a375
3 changed files with 32 additions and 2 deletions

View File

@@ -285,6 +285,8 @@ class Document(BaseDocument):
try:
collection = self._get_collection()
if self._meta.get('auto_create_index', True):
self.ensure_indexes()
if created:
if force_insert:
object_id = collection.insert(doc, **write_concern)