How to add missing dates to data

Hi Takis, Thank you for your response, I’m a bit confused on what you did.

The first thing I was unsure of was if this was all supposed to be in one collection:

db.collection.countDocuments ([
  [
    {
      "date": 0
    },
    {
      "date": 1
    },
    {
      "date": 2
    },
    {
      "date": 3
    },
    {
      "date": 4
    },
    {
      "date": 5
    },
    {
      "date": 6
    },
    {
      "date": 7
    },
    {
      "date": 8
    },
    {
      "date": 9
    }
  ],
  {
    "update": "dates",
    "updates": [
      {
        "q": {},
        "u": [
          {
            "$addFields": {
              "date": {
                "$add": [
                  "2021-08-01T00:00:00Z",
                  {
                    "$multiply": [
                      "$date",
                      24,
                      60,
                      60000
                    ]
                  }
                ]
              }
            }
          }
        ],
        "multi": true
      }
    ]
  },
  {
    "aggregate": "dates",
    "pipeline": [
      {
        "$match": {
          "$expr": {
            "$and": [
              {
                "$gte": [
                  "$date",
                  {
                    "$dateFromString": {
                      "dateString": "2021-08-01T00:00:00"
                    }
                  }
                ]
              },
              {
                "$lte": [
                  "$date",
                  {
                    "$dateFromString": {
                      "dateString": "2021-08-05T00:00:00"
                    }
                  }
                ]
              }
            ]
          }
        }
      },
      {
        "$lookup": {
          "from": "orders",
          "let": {
            "datesDate": "$date"
          },
          "pipeline": [
            {
              "$match": {
                "$expr": {
                  "$eq": [
                    {
                      "$dateToString": {
                        "format": "%Y-%m-%d",
                        "date": "$$datesDate"
                      }
                    },
                    {
                      "$dateToString": {
                        "format": "%Y-%m-%d",
                        "date": "$date"
                      }
                    }
                  ]
                }
              }
            }
          ],
          "as": "found-orders"
        }
      },
      {
        "$project": {
          "_id": 0
        }
      }
    ],
    "cursor": {},
    "maxTimeMS": 1200000
  }
  
]);

Also, is all of this supposed to be within my:

rderRouter.get(
 '/summary',
 isAuth,
 isAdmin,
 expressAsyncHandler(async (req, res) => {

}

The formatting was also a bit confusing for me. In the way I had been formatting my code, something like $addFields would be written without quote, but in your code you use quotes ("$addFields"). Why is that? Similarly, I had been within the Order.aggregate([ ]) method not the db.collection.countDocuments ([ ]) method, is it necessary to use db.collection.countDocuments ([ ])? Why?

And lastly, since I don’t have a specific start date (it all depends on when the first order was made), would I supplement '$createdAt' where "2021-08-01T00:00:00Z" was within the "$add" array? Unlike the example, I also don’t have a specific start and end date, so should I still include the code after "$match", and if so, what dates would I include for the "$gte " and "$lte" ? $first: { '$ceatedAt' } and $last: { '$ceatedAt' } ?