Skip to content

Update all EmbeddedDocument at once #2019

Open
@teamhide

Description

@teamhide

Here is my models.

class Attachment(EmbeddedDocument):
    path = StringField(required=True)
    is_deleted = BooleanField(default=False)

class Test(Document):
    test_id = SequenceField()
    attachments = ListField(EmbeddedDocumentField(Attachment), required=False)

Until now, to set is_deleted=True all embedded document, I used below code.

test = Test.objects(test_id=test_id)
for attachment in test.attachments:
    delete_attachments(test_id=attachment.test_id)

def delete_attachments(test_id: int) -> None:
    Test.objects(
        test_id=test_id,
    ).update(set__attachments__S__is_deleted=True)

Is it a only way to update all document?

Is there any update_all method here?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions