Converting AggregationOperation

I have such an aggregation, and I have problems with its execution.
I need to pass parameters to reduce that look like objects with fields, but the problem is that when the aggregation is performed, some of my fields are not converted to aggregate functions.
I attach the aggregation itself, the Java code that collects this aggregation, and what this aggregation looks like after executing the query.
Is it possible to fix this somehow?
Before this, everything was written in Document, but now I need to rewrite the aggregation classes

{
   "aggregate":"__collection__",
   "pipeline":[
      {
         "$addFields":{
            "created_at_date":{
               "$dateToString":{
                  "format":"%Y-%m-%dT00:00:00Z",
                  "date":"$created_at"
               }
            }
         }
      },
      {
         "$group":{
            "_id":"$created_at_date"
         }
      },
      {
         "$addFields":{
            "isoDate":{
               "$toDate":"$_id"
            }
         }
      },
      {
         "$sort":{
            "isoDate":-1
         }
      },
      {
         "$group":{
            "_id":null,
            "dates":{
               "$push":"$isoDate"
            }
         }
      },
      {
         "$project":{
            "_id":1,
            "continuousCount":{
               "$reduce":{
                  "input":{
                     "$range":[
                        1,
                        {
                           "$size":"$dates"
                        }
                     ]
                  },
                  "initialValue":{
                     "$java":org.springframework.data.mongodb.core.aggregation.AddFieldsOperation@2139a045
                  },
                  "in":{
                     "$cond":{
                        "if":{
                           "$ne":[
                              "$value.previousDate",
                              {
                                 "$java":org.springframework.data.mongodb.core.aggregation.ArithmeticOperators$Add@62303a4
                              }
                           ]
                        },
                        "then":{
                           "$java":org.springframework.data.mongodb.core.aggregation.AddFieldsOperation@1178f2aa
                        },
                        "else":{
                           "$java":org.springframework.data.mongodb.core.aggregation.AddFieldsOperation@4d3eb120
                        }
                     }
                  }
               }
            }
         }
      }
   ]
}

db.collection.aggregate([
  {
    $addFields: {
      created_at_date: {
        $dateToString: {
          format: "%Y-%m-%dT00:00:00Z",
          date: "$created_at"
        }
      }
    }
  },
  {
    $group: {
      _id: "$created_at_date"
    }
  },
  {
    $addFields: {
      isoDate: {
        $toDate: "$_id"
      }
    }
  },
  {
    $sort: {
      isoDate: -1
    }
  },
  {
    $group: {
      _id: null,
      dates: {
        $push: "$isoDate"
      }
    }
  },
  {
    $project: {
      continuousCount: {
        $reduce: {
          input: {
            $range: [
              1,
              {
                $size: "$dates"
              }
            ]
          },
          // Генеруємо індекси для порівняння
          initialValue: {
            count: 1,
            stopCounting: false,
            previousDate: {
              $arrayElemAt: [
                "$dates",
                0
              ]
            }
          },
          in: {
            $cond: [
              {
                $or: [
                  "$$value.stopCounting",
                  {
                    $ne: [
                      {
                        $add: [
                          {
                            $arrayElemAt: [
                              "$dates",
                              "$$this"
                            ]
                          },
                          86400000
                        ]
                      },
                      "$$value.previousDate"
                    ]
                  }
                ]
              },
              {
                count: "$$value.count",
                stopCounting: true,
                previousDate: "$$value.previousDate"
              },
              {
                count: {
                  $add: [
                    "$$value.count",
                    1
                  ]
                },
                stopCounting: false,
                previousDate: {
                  $arrayElemAt: [
                    "$dates",
                    "$$this"
                  ]
                }
              }
            ]
          }
        }
      }
    }
  },
  {
    $project: {
      _id: 0,
      continuousCount: "$continuousCount.count"
    }
  }
])
    ArrayElemAt arrayElemAt = ArrayElemAt.arrayOf("$dates")
            .elementAt("$this");
    ArithmeticOperators.Add addDay = ArithmeticOperators.Add.valueOf(arrayElemAt)
            .add(86400000);
    RangeOperator rangeOperator = RangeOperator.rangeStartingAt(1).to(Size.lengthOfArray("$dates"));
    ArrayElemAt previousDate = ArrayElemAt.arrayOf("$dates").elementAt(0);
    AddFieldsOperation initialValue = AddFieldsOperation.builder()
            .addFieldWithValue("count", 1)
            .addFieldWithValue("stopCounting", false)
            .addFieldWithValue("previousDate", previousDate)
            .build();
    Criteria neCriteria = Criteria.where("value.previousDate").ne(addDay);
    AddFieldsOperation condValues = AddFieldsOperation.builder()
            .addFieldWithValue("count", "value.count")
            .addFieldWithValue("stopCounting", true)