如何在mongoengine EmbeddedDocument上创建索引?

时间:2019-08-01 11:09:06

标签: python mongodb mongoengine

我有Document和EmbeddedDocument。我想在EmbeddedDocument的字段上创建索引。 这是示例结构以及我尝试过的方法。

from mongoengine import Document, EmbeddedDocument, fields


class Parent(Document):
    meta = {
        'collection': 'parent',
        'indexes': [
            'name',
            'child__name',  # throws mongoengine.errors.LookUpError: Cannot resolve field "child__name"
            'child.name',  # does nothing
        ],
    }
    name = fields.StringField()
    child = fields.EmbeddedDocumentField(Child)


class Child(EmbeddedDocument):
    meta = {
        'indexes': [
            'name',  # does nothing
        ],
    }
    name = fields.StringField()

甚至有可能创建这样的索引吗?

0 个答案:

没有答案