MongoEngine / MongoEngine/mongoengine

Updating nested EmbeddedDocumentListField objects

Open
#2,391 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I have trouble pulling nested embedded objects.

Having a model like the following I know we can remove embedded objects as following:

class TopClass(Document):
name1 = StringField()
somevar = EmbeddedDocumentListField(EmbeddedClass)

class EmbeddedClass(EmbeddedDocument):
name2 = StringField()

topclass = TopClass.objects.get(name1=name)
topclass.update(pull__somevar__name2="whatever")

Is there a way to remove an object one level deeper as follows?

class TopClass(Document):
name1 = StringField()
somevar = EmbeddedDocumentListField(EmbeddedClass1)

class EmbeddedClass1(EmbeddedDocument):
name2 = StringField()
someothervar = EmbeddedDocumentListField(EmbeddedClass2)

class EmbeddedClass2(EmbeddedDocument):
name3 = StringField()

topclass.update(something here)

How can i select some EmbeddedClass1 object with name2="something" and then pull (delete) some EmbeddedClass2 object with name3="somethingelse"? (and then save topclass although update should already do it)

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 with MongoEngine's update and pull handling for the nested EmbeddedDocumentListField model shown in the issue. Verify whether an update can select EmbeddedClass1 by name2 and remove a nested EmbeddedClass2 by name3; done would be a documented answer or a focused behavior change with regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.