I have a yoga app where users complete exercises and press a "complete" button to add the exercise to an array of maps within a Firestore document. Each exercise has a different duration (time) and calorie burn (kcal).
I want to calculate the total time and total kcal each time a new exercise is added to this array. My Firestore structure includes a document for each date. If today's date matches an existing document, I add the completed exercise to that document. If not, I create a new document for the current date and add the exercise to it.
How can I calculate the total_time
and total_kcal
when a new exercise is added to the array in Firestore?