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)
)))
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
Try using this format,
class classEmbed:
t = StringField()
p = StringField()
class Test:
g = ListField(EmbeddedDocumentField(classEmbed))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With