'Can I use an ISO-String like '2022-02' as document id in cloud firestore or would this cause hotspotting?

In my App a user can track his workouts, which I want to save in cloud firestore. My idea is to store a list of workouts for each month to prevent that a document gets too big. So a document would look something like this:

month: '2022-02',
workouts: [
  {
  date: '2022-02-01',
  exercises: [
       {
        sets: [{'reps': 12, 'weight': 80}
               {'reps': 12, 'weight': 80}
            ],
       },
     ],
 },
{
  date: '2022-02-02',
  exercises: [
       {
        sets: [{'reps': 10, 'weight': 90}
               {'reps': 10, 'weight': 90}
            ],
       },
     ],
 },
],

Question:

How to fetch for example the documents of the last three months? What happens if I have lets say 500 documents with an monotionally increasing document ID like an ISO-String 2022-02 for each month. Now I want to fetch all month until 2017-05. Will this cause hotspotting?

What is a good practise when storing data like this?



Solution 1:[1]

The right approach regarding your document IDs is to use the Uuid package. So ideally you don't want to use a date for the identifier of your documents.

Regarding the dates, what you need is to use the where() clause of Firebase APIs in order to retrieve data in a specific date range.

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 Vandad Nahavandipoor