Reputation: 7679
How is it possible to ListField(DictField()) with mongoengine and access it, because the below code does not work?
from mongoengine import *
class Test():
g = ListField(DictField(Mapping.build(
test1=StringField(required=True),
test2=StringField(required=True)
)))
Upvotes: 3
Views: 3450
Reputation: 51
I recognize that this post is very old, but for anyone finding this thread starting on using mongoengine. To improve on Niranj's answer, there now exists an EmbeddedDocumentListField
and you need to inherit from EmbeddedDocument
or Document
in those classes.
class classEmbed(EmbeddedDocument):
t = StringField()
p = StringField()
class Test(Document):
g = EmbeddedDocumentListField(classEmbed)
The documentation is here under Fields
Upvotes: 5
Reputation: 778
Try using this format,
class classEmbed: t = StringField() p = StringField() class Test: g = ListField(EmbeddedDocumentField(classEmbed))
Upvotes: 4