如何使用mongoengine ListField(DictField())并访问它,因为下面的代码不起作用?
from mongoengine import *
class Test():
g = ListField(DictField(Mapping.build(
test1=StringField(required=True),
test2=StringField(required=True)
)))发布于 2017-08-04 10:15:44
我知道这篇文章很老了,但对于任何开始使用mongoengine的人来说,找到这个帖子都是很古老的。为了改进Niranj的回答,现在存在一个EmbeddedDocumentListField,您需要在这些类中继承EmbeddedDocument或Document。
class classEmbed(EmbeddedDocument):
t = StringField()
p = StringField()
class Test(Document):
g = EmbeddedDocumentListField(classEmbed)文档位于字段下的here中
https://stackoverflow.com/questions/25240827
复制相似问题