0

I'm trying to set up an app like snapchat where the snap is gone after 24 hours, but how would I be able to do this with the Firebase's Scheduled Functions with Cloud Functions? I seen their sample code where it's a fixed time period, but the 24 hours depends on when the document is created not everyday at midnight or if a data is being added or modified. This is what I seen that closely resembles an answer I'm looking for but that only works when a data is being created, what if there's a pause of data created and the documents are still there uno.

Mohamed Mohamed
  • 3,965
  • 3
  • 23
  • 40
  • The answer you linked actually runs whenever data is written, as indicated by the `onWrite` in `functions.database.ref('/path/to/items/{pushId}').onWrite((change, context)`. But you'll need to convert it to Cloud Firestore yourself. If you get stuck on doing so, feel free to post a question with the [minimal code that reproduces what *you* tried](http://stackoverflow.com/help/mcve). – Frank van Puffelen Sep 18 '19 at 06:29
  • The conversion of code isn't the problem, the problem is when no user creates a snap then the onWrite is no longer written, in my understanding the previous documents existing longer than 24 hours will not be deleted only until someone creates a new document. – Mohamed Mohamed Sep 18 '19 at 20:51
  • That's the same for Realtime Database, which is why the code in my linked answer listens to any writes to the parent node. In Cloud Firestore the equivalent would be to listen to all writes to the collection. It's a bit overkill, so nowadays I'd probably schedule a Cloud Function every day or so to run the query. – Frank van Puffelen Sep 18 '19 at 22:30

0 Answers0