MongoEngine / MongoEngine/mongoengine

Possibility of embedding a clone of a document as embedded

Open
#1,071 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

My current issue arises from the need of snapshotting documents for later use.

Say I have a

    class User(Document):
        name = StringField()

and a

    class Message(Document):
        message = StringField()
        user = DynamicField()

For every message that the user sends I'd like to save a copy of the user in case the user changes his name, I'd see what the user looked like when he sent the message.
The example might not make any sense but the idea should be clear. Previously (I think < 0.10) I could create a Document by inheriting both Document and EmbeddedDocument, but for some reason that is not possible any more.

How could I implement snapshotting of Documents as EmbeddedDocuments, or if not elegantly possible, it would be a nice feature. I think making multiple inheritance from Document and EmbeddedDocument would be best.

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 reviewing how Document and EmbeddedDocument are defined and how DynamicField stores referenced values. Compare the current inheritance constraints with the requested snapshotting use case, then identify the tests covering document inheritance and embedded documents. Done means the supported behavior and its limitations are documented and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
backend, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.