MongoEngine / MongoEngine/mongoengine
EmbeddedDocumentListField cannot have a primary/unique field?
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
class RatingData(EmbeddedDocument):
id = StringField(unique=True)
rating = IntField()
class Subject(Document):
id = IntField(primary_key=True)
rating = EmbeddedDocumentListField(RatingData)
if not Subject.objects(id=par_subject_id).first() or not Subject.objects(
id=par_subject_id).first().rating:
Subject.objects(id=par_subject_id).upsert_one(rating=[rating_data])
else:
Subject.objects(id=par_subject_id).update_one(push__rating=rating_data)
But there is duplicates in Mongo.


There is the index

Mongoengine 0.18.2
Python 3.8.0
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.
Research direction
Reproduce the Subject and RatingData example on MongoEngine 0.18.2 with MongoDB, starting from EmbeddedDocumentListField and the unique=True and primary_key declarations. Compare the behavior of upsert_one and push__rating with the displayed index. Done means establishing whether uniqueness is expected for embedded list fields and recording the confirmed behavior or required change with a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100