MongoEngine / MongoEngine/mongoengine
how to delete from filelist = ListField(FileField())
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 a listField for storing file list, for example, filelist = ListField(FileField())
how can I delete one file from this list? I try to get one file then use file.delete(), it really deletes the file from fs.files, but from filelist, you can still have two object id inside, like
"filelist" : [
ObjectId("5b6b45ab360e2eceefa39f18"),
ObjectId("5b6b5735360e2ed0cad8e9f7")
],
But if I try to use pull like
Classname.objects(id=pk).update_one(pull__filelist=file), it throws error "bson.errors.InvalidDocument: Cannot encode object: <GridFSProxy: 5b6b5735360e2ed0cad8e9f7>"
How can I deal with that? Please help, thank you.
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
Start by reproducing the ListField(FileField()) behavior described in the issue, including deletion through file.delete() and the pull__filelist update. Inspect the FileField, ListField, and GridFSProxy handling involved in that update and determine what behavior should remove the stored reference as well as the file. Done means the failing update path has a documented or tested resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100