hmarr/mongoengine — Issue #444: Covered Index - support for inherited classes
Author: rozza
Created: 2012-03-02 09:39:03+00:00
State: open

Mongoengine doesn't support covered indexes because `QueryFieldList` doesn't handle exclusion of _id and inclusion of other fields.

Also, its broken with inheritance as if a class has allow_inheritance on then `_cls` is automatically added to the field list, this is problematic as there are no indexes on _cls, just _type. #437 wil help with this but it should be possible to use covered indexes with it on.

The following example should be able to use IndexOnly:

```
class Test(mdb.Document):
a=mdb.IntField()

meta = {
'indexes': ['a']
}

obj = Test(a=1)
obj.save()

print Test.objects(id=obj.id).exclude('a').explain()
print Test.objects(id=obj.id).exclude('a').first().id

print Test.objects(id=obj.id).only('id').explain()
print Test.objects(id=obj.id).only('id').first().id

print Test.objects(a=1).exclude('id').explain()
print Test.objects(a=1).exclude('id').first().a

print Test.objects(a=1).only('a').explain()
print Test.objects(a=1).only('a').first().a
```