Skip to content

$push and $position operators do not work with list in embedded document #1965

@tjhall13

Description

@tjhall13
    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')})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions