MongoEngine / MongoEngine/mongoengine
How to use Embedded Document in bulk insert
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
I'm using this model
class Schedule(EmbeddedDocument):
scheduleId: StringField(required=True)
detail: StringField()
class AccountBalance(Document):
memberID = StringField(required=True)
schedule = ListField(EmbeddedDocumentField(Schedule))
array = []
for index, row in df.iterrows():
# handle schedule
schedule = Schedule()
schedule.scheduleId = "1234667777"
schedule.detail = "some random detail"
payload = {
"memberID": "98765",
"schedule": schedule,
}
array.append(payload)
person_instances = [TrialBalance(**data) for data in array]
AccountBalance.objects.insert(person_instances, load_bulk=False)
If I comment out code for schedule class (Embedded document), the code works like charm but when I try to run this code, it throws an error
The source SON object needs to be of type 'dict' but a '<class 'str'>' was found
Can someone tell me how to use the embedded document in bulk insert or how to fix this error??
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
The issue provides no repository file or test to start from. Reproduce the shown AccountBalance.objects.insert(...) path with the Schedule and payload examples, then use the embedded-document and bulk-insert behavior as the completion check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100