How to add missing dates to data

Personally, I would implement the idea expressed in Takis’ link at the application level in the code you shown above, rather than having the database server do it. I would use an array of dates, for all dates of interest, with a default order count of 0. I would then take dailyOrders to complete the array of dates with the count of orders received.

Why?

  1. It reduces the workload of the server.
  2. It reduces the bandwidth needs between the server and the application.
  3. It increases the chances to distribute this workload to the multiple application instances.
  4. It allows to have a more flexible API because you could have one /summary-non-zeros and /summary-with-zeros rather than only /summary. You would use /summary-with-zeros to provide an enriched result for /summary-with-zeros.