How project all day between two date?

First, having date as string rather than the data data type is not a good idea. String takes more space, are slower to compare and you cannot use the rich date API.

What you are trying to do is probably easier to do in your application code rather that try to do it on the server. Also doing on the server will increase the data transferred from the server to the application.

To transform an array from one form to the other you need to use $map.

The issue you have is to generate all the days between your 2 dates because you are using string. Your example is easy because you are within the same month. Difficulties will appears when your start and end date is in different months, worst when it start in February. All these difficulties are already solve if you use date data type.

1 Like