问题
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!
回答1:
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
While these are for the Firebase Realtime Database, the same approach applies to Cloud Firestore.
来源:https://stackoverflow.com/questions/50952834/how-to-create-an-auto-delete-mechanism-for-firestore-deleting-data-after-time