How to trigger a cloud function based on a timestamp attribute of a firestore document

AlejandroEndo

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

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to update timeStamp field in a firestore document from cloud function?

How to access root document when using a firestore trigger (onUpdate) in my cloud function?

How to update or set property of firestore document after .onCreate cloud function trigger

Is there's an way to trigger an function based on firestore document read?

Delete document in Firestore with Cloud Firestore update trigger

How to save Document Reference from Cloud Function in Cloud Firestore?

How to Trigger Firestore function on Creation of Sub Document in a sub Collection

cloud function trigger on create document

Cloud function trigger on document update

Trigger Firebase Cloud Function on inserting to Cloud Firestore document for the first time with given uid

How to access firestore.Timestamp from Firebase Cloud Function

How to get a document from a Cloud Firestore collection based on index?

Get Document in Firestore Cloud Function

how to use reusable code for Google Cloud Function Firestore trigger?

Query from Cloud Firestore by timestamp in Cloud Function

Cloud Function's Cloud Firestore trigger

Cloud Firestore trigger for Cloud Function to invoke Composer

Trigger cloud function when a specific condition resulting from the comparison of document fields in firestore is true

Access a cloud firestore document within a cloud function

Update Property on Firestore Document Based on a timestamp property in same document

How to move a document in Cloud Firestore?

Firestore cloud function trigger with wildcard path

How to add server TimeStamp in Firestore document android

Compare Firestore timestamp with NodeJS timestamp in google cloud function

firestore cloud function update another document

retrieve Firestore document from onCreate trigger with Cloud Functions

Cloud Firestore triggers " Your trigger must always point to a document"

How do Firestore (authentication) rules see cloud function reads/writes and trigger function reads/writes?

Cloud Firestore How to subtract hour from Timestamp