我有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()
甚至有可能创建这样的索引吗?