-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Milestone
Description
We already have to_json() and from_json(data), but the later only creates a whole new Document. My problem is, that I need to update only certain fields and the document is already loaded.
It would be nice to be able to load a partial json representation of a Document and only update the passed fields.
Example:
>>> class Test(Document):
... name = StringField()
... foo = StringField(default="bar")
...
>>> t = Test()
>>> t.save()
<Test: Test object>
>>> t.to_json()
'{"_id": {"$oid": "5198cf4759055e1762366812"}, "foo": "bar"}'
>>> t.from_json('{"name": "Baz!"}', update_inplace=True)
<Test: Test object>
>>> t.name
u'Baz!'Here from_json with update_inplace=True would return self and not a new Test object.
Alternatively an update_from_json function could do the same.
Reactions are currently unavailable