In MongoEngine, we often need to store a list of embedded documents in one document. The traditional way is to use ListField(EmbeddedDocumentField(document_type))
, which is a bit cumbersome.
EmbeddedDocumentListField
can make things easier. Here's an example.
Before:
from mongoengine import Document, ListField, EmbeddedDocumentField
class Post(Document):
comments = ListField(EmbeddedDocumentField(Comment))
After:
from mongoengine import Document, EmbeddedDocumentListField
class Post(Document):
comments = EmbeddedDocumentListField(Comment)