Merge pull request #1114 from gmacon/sparse-compound

Allow sparse compound indexes
This commit is contained in:
Omer Katz 2015-12-10 07:27:22 +02:00
commit 0372e07eb0
3 changed files with 15 additions and 4 deletions

View File

@ -6,6 +6,7 @@ Changes in 0.10.6 - Dev
======================= =======================
- Add support for mocking MongoEngine based on mongomock. #1151 - Add support for mocking MongoEngine based on mongomock. #1151
- Fixed not being able to run tests on Windows. #1153 - Fixed not being able to run tests on Windows. #1153
- Allow creation of sparse compound indexes. #1114
Changes in 0.10.5 Changes in 0.10.5
================= =================

View File

@ -839,10 +839,6 @@ class BaseDocument(object):
if index_list: if index_list:
spec['fields'] = index_list spec['fields'] = index_list
if spec.get('sparse', False) and len(spec['fields']) > 1:
raise ValueError(
'Sparse indexes can only have one field in them. '
'See https://jira.mongodb.org/browse/SERVER-2193')
return spec return spec

View File

@ -863,6 +863,20 @@ class IndexesTest(unittest.TestCase):
self.assertTrue([('provider_ids.foo', 1)] in info) self.assertTrue([('provider_ids.foo', 1)] in info)
self.assertTrue([('provider_ids.bar', 1)] in info) self.assertTrue([('provider_ids.bar', 1)] in info)
def test_sparse_compound_indexes(self):
class MyDoc(Document):
provider_ids = DictField()
meta = {
"indexes": [{'fields': ("provider_ids.foo", "provider_ids.bar"),
'sparse': True}],
}
info = MyDoc.objects._collection.index_information()
self.assertEqual([('provider_ids.foo', 1), ('provider_ids.bar', 1)],
info['provider_ids.foo_1_provider_ids.bar_1']['key'])
self.assertTrue(info['provider_ids.foo_1_provider_ids.bar_1']['sparse'])
def test_text_indexes(self): def test_text_indexes(self):
class Book(Document): class Book(Document):