I have a couple of collections that have history_days set to null in order to maintain a document history that is used by our app. I was about to implement soft delete (or “trash”) functionality for those collection but then I realised that Delete actually merely adds a “delete” event to the collection/document history.
In theory it means that to get all “deleted” documents I need to get all “delete” events for the collection. And to restore the document I could delete the “delete” event.
A couple of things that came to mind though:
Does this mean that nothing is ever actually deleted from a collection that has history_days set to null?
Is this a sensible approach of a “soft-delete” like functionality?
Is there actually a way to get a list of events of a particular type? I’d assume it’s not trivial as you can’t really create an index on events
That is right. Document is marked Delete and from there on any Read operation (Get or Paginate) will not be able to fetch it. Having history_days to null can impact query performance if you have too many events on a document.
Yes, because you can always Remove the Delete event to make the document active again (Analogy of recovering a file back from Trash).
There is no built in function but here is an example to identify all documents that are deleted in a collection today ??
Create an Index sorted asc(default) on ts field of the collection.