skip to Main Content

I have a Firestore database that consists of records with an "endDate" field. Based on this field I want to delete some records once a day and run a cron job for them. For example, if today is November 22, 2023 and the end date is November 21, 2023, I want that record to be removed from the database. How can I achieve this? Thank you

2

Answers


  1. You can create a firebase cloud function that for example runs Node.js code everyday at 0:00.

    const functions = require("firebase-functions");    
    
    exports.deleteEntries = functions.pubsub.schedule("0 0 * * *")
        .onRun(() => {
        //delete here
    })
    

    "0 0 * * *" is a cron expression, examples

    One job lies way in the capacity of cloud functions’ free tier too.

    Login or Signup to reply.
  2. You can leverage Firestore’s Time-To-Live feature to have the system automatically remove "stale" documents.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search