Open
Description
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().