1

I am trying to make some documents disappear according to a date attribute that it contains, I tried to use cloud scheduler but it does not allow me to dynamically specify the date of execution of the cloud function.

Chris32
  • 4,716
  • 2
  • 18
  • 30
  • 1
    It sounds like you need your function to query for documents to delete at the current moment in time. Cloud Scheduler isn't going to be able to tell you that. – Doug Stevenson Jul 22 '19 at 21:20

1 Answers1

0

I just replicated your use case scenario and I successfully deleted documents from Cloud Firestore based on its field timestamp.

For this, I just created a cloud function following this Quickstart using a server client library

Then I added some documents with a timestamp field populated with future and past timestamps.

Then modified the Quickstart Function to implement the delete document method as shown in this Delete data from Cloud Firestore documentation inside of an if conditional.

In the if conditional just check if the timestamp it's older than the current time and deletes the document. You can see my function code here.

After that to keep the function constantly running just implemented a Cloud Scheduler following this Cloud Scheduler quickstart, setting the Cloud Function Url as the target for this Scheduler. Since Cloud Scheduler only handles time as a Frequency you can't use it to dynamically set dates to run the job.

Chris32
  • 4,716
  • 2
  • 18
  • 30