Soft deletes allow data to be hidden from application queries while remaining stored in the database, useful for retention policies and recovery scenarios. Two main approaches are covered: field flagging (adding a `deletedAt` timestamp field) and archive collections (moving documents to a separate collection). Using the MongoDB Java Sync driver 5.6, the guide walks through priming collections, performing soft deletes, filtering queries to exclude deleted documents, creating compound indexes, recovering documents, cascading deletions to related collections, and automating cleanup with MongoDB TTL indexes. Pros include fast recovery and compliance support; cons include extra storage, query complexity, and risk of inconsistent states.

13m read timeFrom foojay.io
Post cover image
Table of contents
What are soft deletes?How can soft deletes be approached?Implementation of soft deletesPros and cons of soft deletesWrap Up

Sort: