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

╄→гoц情女王★ 提交于 2020-03-17 12:20:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!