ListField(DictField()) with mongoengine



如何使用mongoengine访问ListField(DictField())并访问它,因为下面的代码不起作用?

from mongoengine import *
class Test():
    g = ListField(DictField(Mapping.build(
    test1=StringField(required=True),
    test2=StringField(required=True)
)))

我知道这篇文章很老了,但是对于任何发现这个线程开始使用蒙古引擎的人。为了改进Niranj的答案,现在存在一个EmbeddedDocumentListField,你需要从这些类中的EmbeddedDocumentDocument继承。

class classEmbed(EmbeddedDocument):
    t = StringField()
    p = StringField()
class Test(Document):
    g = EmbeddedDocumentListField(classEmbed)

文档在Fields

下面

尝试使用这个格式,

<>之前类classEmbed:t = StringField()p = StringField()类测试:g = ListField(EmbeddedDocumentField(classEmbed))

最新更新