Skip to content

document.update(**kwargs) writes to MongoDB but not updating fields of document #650

Open
@DirectX

Description

@DirectX

Seems like batch updating with document.update(**kwargs) only affects DB, not current document. Here is an example:

from mongoengine import *

connect("test")


class SomeDocument(Document):
    title = StringField()

    def __unicode__(self):
        return self.title


SomeDocument.drop_collection()

doc = SomeDocument(title="Initial title")
doc.save()

print "Updating fields one by one and finally save()"
doc = SomeDocument.objects[0]
doc.title = "New title 1"
doc.save()
doc_reloaded = SomeDocument.objects[0]
print "Saved: %s, Loaded: %s" % (doc, doc_reloaded)

print ""

print "Batch updating with document.update(**kwargs)"
doc = SomeDocument.objects[0]
doc.update(**{ "set__title": "New title 2" })
doc_reloaded = SomeDocument.objects[0]
print "Saved: %s, Loaded: %s" % (doc, doc_reloaded)

Output

Updating fields one by one and finally save()
Saved: New title 1, Loaded: New title 1

Updating with update()
Saved: New title 1, Loaded: New title 2

Expected behaviour is to update field's values after performing update().

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions