MongoEngine / MongoEngine/mongoengine

how to delete from filelist = ListField(FileField())

Open
#1,835 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Enhancement Question
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.