1

I am creating an app that needs to delete documents automatically after a timer that is stored inside of the document expires but I am not seeing any data types that support a timer, the closest thing I found was an integer but I am not exactly sure on how I would go about updating that every second. Here is an example of my previous attempt at adding a timer as a field.

                      FirebaseFirestore.instance.collection("docs").add({
                        "timer:": Timer(Duration(hours: 1), () {
                          print('Finished');
                          _deleteDocument();
                        })
                      });
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Cameron Johnson
  • 143
  • 1
  • 10
  • 1
    Updating a document every second is quite wasteful. You should either store the start timestamp and the interval (both of which are fixed) and/or the expiration timestamp. Based on those you have all you need to delete the document when it's time. --- I linked a few questions where such a time-to-live is further discussed, and which include many more links. – Frank van Puffelen Jan 29 '22 at 22:06

0 Answers0