Is this the best way to model budget data in NOSQL?

Viewed 72

I am using Firestore but I am not convinced that I modeled the data of my application as good as it could be.

I need to model a relationship between categories, the amount spent on each category and the budget for each category, for every month, for every year, for each user individually. I am currently using a (Where Query Based) approach to get the required documents from scrambled documents. The following is how my data is modeled(Sorry for making it verbose):

user987(doc)
  |
 categories(Non-Root Collection)
        |
         \ /xyz(doc)
           icon:'Food',
           iconIndex:15,
           category:'Refreshments
        |
         \ /abc(doc)
           icon:'Car',
           iconIndex:5,
           category:Vehicle
        |
        ...

 amounts(Non-Root Collection)
     |
      \ /1111(doc)
        year:2018,
        month:January,
        January: {
          budget:0.0
          spent:0.0
        },
       categoryRefernce:/xyz
     |
      \ /2222(doc)
        year:2018,
        month:February,
        February: {
         budget:0.0
         spent:0.0
        },
       categoryRefernce:/xyz
     |
      \ /3333(doc)
        year:2018,
        month:March,
        March: {
          budget:0.0
          spent:0.0
        },
       categoryRefernce:/xyz
     |
      \ /4444(doc)
        year:2018,
        month:April,
        April: {
         budget:0.0
         spent:0.0
        },
       categoryRefernce:/xyz
     |
    ...
    ...
     |
      \ /9999(doc)
        year:2018,
        month:December,
        December: {
         budget:0.0
         spent:0.0
        },
       categoryRefernce:/xyz
     |
      \ /7878(doc)
        year:2018,
        month:January,
        January: {
         budget:0.0
         spent:0.0
        },
       categoryRefernce:/abc <-- Different Category
      |
     ...
     ...
      |
       \ /7878(doc)
        year:2018,
        month:December,
        December: {
         budget:0.0
         spent:0.0
        },
       categoryRefernce:/abc
      |
      \ /7878(doc)
        year:2019,<-- Different year
        month:January,
        January: {
         budget:0.0
         spent:0.0
        },
       categoryRefernce:/xyz
      |
     ...

Each category has 12 months associated to them with specific budgets and spent amounts and these categories can span over many years. I also aggregate a lot of this data into totals.I have tried many other ways to model this kind of data but non of them allow me to query effectively, but I am still not so sure about this approach and if it will hold when the data scales. Are there any other ways to model this kind of data effectively?

Thanks in advance - Matt

0 Answers
Related