google-cloud-platformgoogle-cloud-firestore

How to define period of time to delete TTL firestore Google cloud


I have a firestore database and I am checking the ttl solution for deleting old documents.

I have a field called date that I want that after two years have passed by that field, the record is deleted. Is any way to define this? Or I should create a new field called TTL and do the transformation there?

Edit: I know I can use different forms for TTL. My question is for example, in the ttl field I have this date: 12/31/2024. When is this document deleted? Can I said, delete it after a year has passed by that date?


Solution

  • You can use any field name for the TTL, it doesn't have to be called TTL. I recommend checking out the documentation here for how to set it up.

    Update: the field that you identify in the TTL policy determines the exact timestamp that the document will be deleted. There is no way to configuration an offset to that timestamp in the policy. If you want to delete at an offset, you'll have to add an additional field to the document with the effective deletion timestamp.