Add new meta option to Document: allow_index_creation.

Defaults to True. If set to False then MongoEngine will not ensure indexes exist
This commit is contained in:
Colin Howe
2012-03-19 20:27:08 +00:00
parent 61411bb259
commit 7e376b40bb
3 changed files with 77 additions and 47 deletions

View File

@@ -740,6 +740,28 @@ class DocumentTest(unittest.TestCase):
self.assertEqual(info.keys(), ['_types_1_user_guid_1', '_id_', '_types_1_name_1'])
Person.drop_collection()
def test_disable_index_creation(self):
"""Tests setting allow_index_creation to False on the connection will
disable any index generation.
"""
class User(Document):
meta = {
'indexes': ['user_guid'],
'index_allow_creation': False
}
user_guid = StringField(required=True)
User.drop_collection()
u = User(user_guid='123')
u.save()
self.assertEquals(1, User.objects.count())
info = User.objects._collection.index_information()
self.assertEqual(info.keys(), ['_id_'])
User.drop_collection()
def test_embedded_document_index(self):
"""Tests settings an index on an embedded document
"""