Optional date clause in mongo db query

@Anum Cannot run query: missing required parameters: #{"createdAt" "enddate"}
I don't know what you're trying to do, but have you tried just do this:

[[
  {
    "$match": {
      "$and": [
        {
          "$expr": {
            "$gte": [
              "$createdAt", {{startdate}}
            ]
          }
        },
        {
          "$expr": {
            "$lt": [
              "$createdAt", {{enddate}}
            ]
          }
        }
      ]
    }
  },
]]