class Author(EmbeddedDocument):
name = StringField()
genres = ListField(db.StringField())
class Book(Document):
author = EmbeddedDocumentField(Author)
title = StringField()
text = StringField()
book = Book(
title='Hello World', text='Lorem ipsum dolor sit amet',
author=Author(name='John Doe', genres=['Mystery']))
book.save()
book.modify(push__author__genres__0='Fiction')
Running the above code results in the error:
mongoengine.errors.OperationError: Update failed (The field 'author' must be an array but is of type object in document {_id: ObjectId('5c087e326241ea797f8fab93')})