MongoEngine / MongoEngine/mongoengine

Add possibility to update a document or a whole query from JSON

Open
#323 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement
Dominant language
Python
Stars
4.3k
Forks
1.2k
Avg merge
4h 41m
Merged PRs (30d)
11

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing from_json and to_json entry points and any related tests. Clarify whether the scope is partial in-place document updates, query updates, or both, then define the return and field-update semantics and add coverage for the example behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.