'Firestore best practices: Make one document per entry or group entries of a given month within one document

I am doubting myself on how I should approach this problem.

My users are able to record many parts of their day, including activities, mood, health measurement (heart bpm, glucose), exercise, meals.

I originally thought that I should create one document per entry (i.e. one entry per day). However, when displaying data to the user it rarely occurs on a day by day basis but more on a month by month (charts).

Should I model my Firestore DB in relation to my views or would it be better to just save each entry for each day and then just query?

I am just thinking that it will be more efficient in many parts of the app to have the entries grouped by month than by day.

Am I thinking this right or is there really no benefit? (i.e. maybe the amount of data transferred offsets the costs of unnecessary queries).



Solution 1:[1]

If you plane to save each entry for each day and then just query and query to find the result. The more document you'll have, the more document you will query and it will increase you're read/day and so may be more expensive than in a month by month.

To answer your last question :
Let's take an example : if you have a collection with 100 documents.
And you want to query 20 of it. It will only count as 20 read and not 100 as we might expect.
Just to remind that with firebase you can read up to 50k/day for free, after this limit is it 0.06$/100k read.

I hope it will help you.
Have a nice day !

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Quentin AM