0
votes

I am trying to figure out the best way to execute my cloud function for my firestore database, when data is being read.

I have a field on all of my documents with the timestamp of when the document was last used, this is used to delete documents that haven't been used in two days. The deletion is done by another cloud function.

I want to update this field, when the documents is being used AKA read from my db. What would be the best way to do this?

onWrite(), onCreate(), onUpdate() and onDelete() is not an option.

My database is used by a Android App written in Kotlin.

1
One possibility could be to call a Cloud Function to get (i.e. read) the data, for example a Callable Functions, see firebase.google.com/docs/functions/callable. However there might be better/smarter approaches :-) ... curious to see other answers.Renaud Tarnec

1 Answers

1
votes

There are no triggers for reading data. That would not be scalable to provide. If you require a last read time, you will have to control access to your database via some middleware component that you write, and have all readers query that instead. It will be responsible for writing the last read time back to the database.

Bear in mind that Firestore documents can only be written about once every second, so if you have a lot of access to a document, you may lose data.