How to pass collection name from my local mongodb?

I converted a query into code to run in springboot

public List<POJO_class> compareReport(){
            UnionWithOperation unionWith = UnionWithOperation.unionWith("collection2");

            ProjectionOperation convertStartDateOp = Aggregation.project("stationId", "gapStartTimeStamp", "gapEndTimeStamp")
                    .and(StringOperators.Substr.valueOf("gapStartTimeStamp").substring(0, 10))
                    .as("gapStartDate")
                    .and(StringOperators.Substr.valueOf("gapEndTimeStamp").substring(0, 10))
                    .as("gapEndDate");

            GroupOperation countOp = Aggregation.group("stationId", "gapStartDate", "gapEndDate").count().as("count");
            MatchOperation matchOp = Aggregation.match(Criteria.where("count").gt(1));

            AggregationResults<POJO_class> aggregate = mongoOps.aggregate(
                    Aggregation.newAggregation(
                            unionWith,convertStartDateOp,countOp, matchOp
                    )
                    ,mongoOps.getCollectionName(POJO_class.class),POJO_class.class);
            return aggregate.getMappedResults();

Now, the problem is in the very first line I’m using Union

public List<POJO_class> compareReport(){
            UnionWithOperation unionWith = UnionWithOperation.unionWith("collection2");

Here I have to put the. collection name in string.
Now, my collection is saved in local mongodb. If I’m directly passing this collection then, it’s not working.
To be very precise –
I have to compare the recent two collection which is in my local mongodb, so as the first collection can already be fetched by the POJO class (recent collection), but the collection2 which was saved before this collection(or in the previous run). how to fetch that