title: How to create incremental range aggregation in mongoose from a query parameter. i.e. create an incremental range from a field value
body: <p><strong>So the data set looks like this:</strong>
  <a href="https://i.stack.imgur.com/zQ1G0.png" rel="nofollow noreferrer">screenshot of the data structure</a></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{
    "YearWeekISO": "2020-W53",
    "FirstDose": 0,
    "FirstDoseRefused": "",
    "SecondDose": 0,
    "DoseAdditional1": 0,
    "DoseAdditional2": 0,
    "UnknownDose": 0,
    "NumberDosesReceived": 0,
    "NumberDosesExported": 0,
    "Region": "AT",
    "Population": "8901064",
    "ReportingCountry": "AT",
    "TargetGroup": "ALL",
    "Vaccine": "JANSS",
    "Denominator": 7388778
  }, {
    "YearWeekISO": "2020-W53",
    "FirstDose": 0,
    "FirstDoseRefused": "",
    "SecondDose": 0,
    "DoseAdditional1": 0,
    "DoseAdditional2": 0,
    "UnknownDose": 8,
    "NumberDosesReceived": 0,
    "NumberDosesExported": 0,
    "Region": "AT",
    "Population": "8901064",
    "ReportingCountry": "AT",
    "TargetGroup": "ALL",
    "Vaccine": "UNK",
    "Denominator": 7388778
  },</code></pre>
  </div>
  </div>
  </p>
  <p><a href="https://opendata.ecdc.europa.eu/covid19/vaccine_tracker/json/" rel="nofollow noreferrer">link to the data set</a></p>
  <p>The query parameters will look like :</p>
  <blockquote>
  <p>GET /vaccine-summary?c=AT&amp;dateFrom=2020-W10&amp;dateTo=2020-W53&amp;range=5</p>
  </blockquote>
  <p>where</p>
  <p>c, country code to get report for</p>
  <p>dateFrom, yyyy-Www, eg. 2020-W10 (Including)</p>
  <p>dateTo, yyyy-Www, eg, 2020-W20 (Excluding)</p>
  <p>rangeSize, number, eg, the period for which to calculate metrics</p>
  <p>After applying the aggregation, you should have a transformed data set that looks like :</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{
    "summary": [{
        "weekStart": "2020-W10",
        "weekEnd": "2020-W15",
        "NumberDosesReceived": 1000
      },
      {
        "weekStart": "2020-W15",
        "weekEnd": "2020-W20"
        "NumberDosesReceived": 2000
      }, …
      till end of range(dateTo)
    ]
  }</code></pre>
  </div>
  </div>
  </p>
  <p>}</p>
  <p>Notice how the weekStart incremental from 2020-W10 to 2020-W15, similar with weekEnd.</p>
  <p>NumberDosesReceived is the sum of NumberDosesReceived fileld within that range</p>