Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an auto delete mechanism for firestore? (deleting data after time period) [closed]

I am not sure how to start/accomplish this, I am want the documents in a collection in a firestore database to delete themselves if the document was not changed or accessed for a certain time period (for example 30 days). In other words, the data should expire (be removed) if not needed.

Is there any way to accomplish this task?

Thank you for your help!

like image 595
jonasxd360 Avatar asked Jun 20 '18 16:06

jonasxd360


1 Answers

There is no built-in time-to-live mechanism in Cloud Firestore. The common approach is to run a piece of code at an interval, e.g. a Cloud Function triggered by something like cron-job.org.

Have a look at these questions for samples:

  • Delete firebase data older than 2 hours
  • How to delete firebase data after "n" days
  • Impelementing aging in a Firebase real time database
  • How to schedule a Cloud Functions to run in the future in order to build a Firestore document TTL

While these are for the Firebase Realtime Database, the same approach applies to Cloud Firestore.

like image 78
Frank van Puffelen Avatar answered Sep 28 '22 03:09

Frank van Puffelen