Search code examples
faunadb

Rollback / Un-delete documents in FaunaDB


In FaunaDB, I would like to:

  1. Un-delete a document
  2. List deleted documents by collection

How would I go about doing this?


Solution

    1. You would need to Remove() the "delete" event of that document.
    Remove(docRef, timestamp, "delete")
    

    In order to know the timestamp of those events, you can Paginate() for the Events() of that document and get that info, assuming your document was not garbage-collected:

    Paginate(Events(docRef))
    
    1. You would need an index that covers the references of your documents, and then you can Paginate() for the Events() of that index and filter for "remove" actions. Let's assume you have the index "all_posts":
    Filter(
      Paginate(Events(Match(Index("all_posts")))),
      event => Equals("remove", Select("action", event))
    )