How should I dynamically query the data per month?

I’ll be using reactjs and chartjs to create this. Though I do not have the codes yet, I would only like to ask for advice or to have a better understanding before coding it. In firestore, I already have this data:

enter image description here

I wanted to dynamically query it per vaccine and per month. What I somewhat thought of to do was to have a selection for the user to choose what year and what type of vaccine. I kind of thought of these codes however, dynamically querying it per month was quite difficult:

the selectedVaccine – is the variabale for the select where users can choose what type of vaccine.

db.collection("users") .where("doses.selectedVaccine","==", selectedVaccine) .where("doses.firstDose","==", true)

Any advice would be appreciated about querying it per month. Thank you.

Answer

db.collection("users")
  .where("doses.selectedVaccine","==", selectedVaccine)
  .where("doses.firstDose","==", true)
  .where("doses.firstDose", ">=" start)
  .where("doses.firstDose", "<" end);
  // change doses.firstDose to whichever date you want to use.

For any start and end date (e.g 1st Jan 2020 and 31st Dec 2020), the above query should return all first doses within that time frame.

Then you can loop through the results and place them in arrays depending on their months. Array of all Januaries first doses in position 0, Array of all Februaries first doses in position 1 etc.

This will involve downloading the full data of all doses for a year. If your intention is just to plot a chart, then consider this solution