parse-community / parse-community/parse-server

Remove files from MongoDB after the associated document is deleted

Open
#6,780 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:feature
Dominant language
JavaScript
Stars
21.4k
Forks
4.8k
Avg merge
7h 45m
Merged PRs (30d)
11

Description

Disclaimer: this is a feature request, but I'm willing to contribute by coding it myself since I already coded a similar solution in many of my projects that already use the Parse Server.


Is your feature request related to a problem? Please describe.
I've been using Parse for quite some time in different projects, but when I create a document with File fields, this becomes a problem when the document or when the field itself is removed/replaced using one of the Parse SDKs (JS, Android, etc) because the reference to the file is removed, but the actual file remains there. After some time the database will be full of orphan files that only occupy space.

Describe the solution you'd like
To solve this problem I created a couple of triggers in my Parse projects (Parse.Cloud.afterSave, Parse.Cloud.afterDelete, etc) to properly remove the files whenever the document that they are associated with is deleted or when the field is remove/updated.

The way I implemented this was by creating an environment variable called DELETE_ORPHANS_FROM where I put the list of classes that should have the files removed when a document is deleted/updated. Like this: DELETE_ORPHANS_FROM=Post,Comment. So in my cloud code I read the content of this environment variable and send a Parse.Cloud.httpRequest to delete any orphan file in the classes that I listed there.

The orphan files in the classes that are not listed in this variable are of course untouched. This gives flexibility to the users if for some reason they want to keep the orphan files in certain classes.

Additional context
Before I start working on this I would like to hear from the maintainers and other members of the community what they think of this new feature. Maybe there is a reason why it was not implemented yet. Or maybe the solution that I'm proposing is not optimal, despite the fact that it works in my projects

Please let me know your thoughts and depending on the feedback I will start working on this.

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

No files, tests, or entry points are named. Start by reviewing Parse Server's existing object and file deletion lifecycle and the maintainer discussion; done would require an agreed scope and implementation for deleting or retaining orphaned files after document deletion or field replacement.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, nodejs
Domain
backend, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.