0

I have data under certain collections that I want to have deleted automatically based on how long the user chooses the data to be inputted in the database for.

Is there a specific google firebase/cloud firestore mechanism / method that I can apply, etc.

How would I go about doing so?

b3dog
  • 125
  • 1
  • 11
  • There is no built-in support for time-to-live in Cloud Firestore. Also see https://stackoverflow.com/questions/47173560/is-there-any-ttl-time-to-live-for-documents-in-firebase-firestore – Frank van Puffelen Mar 08 '18 at 20:23

1 Answers1

1

How about scheduling Cloud Functions?

I didn't create such a mechanism but this seems suitable for your scenario. There's an article on the Google Blog about this approach: https://firebase.googleblog.com/2017/03/how-to-schedule-cron-jobs-with-cloud.html

sarneeh
  • 1,320
  • 1
  • 12
  • 27
  • How could I implement this in my app with Swift? Is there any way to do this without Python or Node.js? – b3dog Mar 08 '18 at 20:08
  • There is no built-in support for time-to-live in Cloud Firestore. Cloud Functions run in Node.js only. You can find a [sample of this in the functions-samples repo](https://github.com/firebase/functions-samples/tree/master/delete-old-child-nodes). – Frank van Puffelen Mar 08 '18 at 20:19
  • So my cloud functions have to get the data from my firestore database (after getting the input from a user on my app) and then delete the entries through a function made in node js? – b3dog Mar 08 '18 at 20:26
  • Yes, probably you'd like to separate this logic in a nodejs Cloud Function (some kind of backend for you). Making this mechanism in a Swift app doesn't seem like a good idea :) – sarneeh Mar 09 '18 at 07:44
  • @sarneeh We need our cloud function to be always monitoring the expiration time stamps of the entries in our Firestore database. The lowest time interval that we can use on a Cron job is 1 minute. Do you guys have any suggestions? – b3dog Mar 09 '18 at 19:19