MongoEngine / MongoEngine/mongoengine
document.update(**kwargs) writes to MongoDB but not updating fields of document
Open
@thedrow is already working on this.
Since Jul 1, 2014.
Discussion
Enhancement
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
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().
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.