Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes in 0.10.6 - Dev
=======================
- Add support for mocking MongoEngine based on mongomock. #1151
- Fixed not being able to run tests on Windows. #1153
- Allow creation of sparse compound indexes. #1114

Changes in 0.10.5
=================
Expand Down
4 changes: 0 additions & 4 deletions mongoengine/base/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,10 +839,6 @@ def _build_index_spec(cls, spec):

if 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

Expand Down
14 changes: 14 additions & 0 deletions tests/document/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,20 @@ class MyDoc(Document):
self.assertTrue([('provider_ids.foo', 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):

class Book(Document):
Expand Down