Map and Reduce Operation in Mongo-Db Query using JAVA - Springboot

Yesss[quote=“Prem_Parmar, post:1, topic:1856, full:true”]
I can not able to do map and reduce operation in java mongodb in ProjectionOperation.

I have project operation in native mongo query like this:

{
    $project: {
        data: {
            $map: {
                input: params.timeArray,
                in: {
                    "key": "$this",
                    "value": { "$cond": [{ "$in": ["$this", "$data.date"] }, "$data", []] }
                }
            }
        }
    }
}

And I also want to do reduce operation in another projection operation like this:

{
    $project: {
        id: 1,
        data: { $reduce: { input: "$data", initialValue: [], in: { $concatArrays: ["$value", "$this"] } } }
    }
}

I have tried this:

ProjectionOperation projectionOperation1 = Aggregation.project()
                .and(VariableOperators.mapItemsOf("data")
                        .as("input")
                        .andApply(context -> new BasicDBObject("value",
                                ConditionalOperators.when(where("$this").in("$data.date"))
                                        .then("$data")
                                        .otherwise(new HashSet<>()))))
                .as("data");

But it didn’t give me desired result.

Any help would be appreciated!!
[/quote]

Yes, “$$this” is reference of the variable