Optimal design for soft delete

Hello experts,

I am designing a soft delete functionality for an application that could evolve to hundreds of millions of documents for each collection.
What can perform better in terms of performance, and overall efficiency as the mongodb is hosted on Atlas:
-Using a trash database for the deleted documents along with audit details.
-Using field like, is_deleted, deletion_date,… Etc, and consider those fields in indexing as the retrieve apis have to consider them always.

Thanks for your help

Hello @Mohammad_Shawahneh
I recommend to go with a seperate collection this will:

  • simplify queries on active documents
  • reduce the no. of documents (the less documents you need to query, the faster you can be)
  • no need for an extra or compound index on the is_deteleted flag



Thanks Michael, I agree with your considerations :+1:t2:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.