Following is my Native MongoDB query and below is the SpringData Mongo API equivalent. I am getting struck on using $map in $project in SpringData Mongo API. Appreciate your help on completing my conversion to API
db.users.aggregate([
{ $match: {$and : [{userType:"200"} },
{ $unwind: "$userOrgMap" },
{
$lookup:
{
from: "users",
localField: "userOrgMap.createdbyuser",
foreignField: "_id",
as: "created_by"
}
},
{$project:{
_id:"$_id",
login:"$login",
firstName:"$firstName",
lastName:"$lastName",
email:"$email",
deactivateFlag:"$deactivateFlag",
createdOn:"$createdOn",
createdBy:{
"$map": {
"input": "$created_by",
"as": "u",
"in": {
"name": { "$concat" : [ "$$u.firstName", " ", "$$u.lastName" ] },
}
}
}
}
},
{ $sort : { createdBy : 1} }
])
Spring Query
Aggregation aggregation = newAggregation(
Aggregation.match(Criteria.where("userType").is(userType)),
Aggregation.unwind("userOrgMap"),
Aggregation.lookup("users", "userOrgMap.createdbyuser", "_id", "created_by"),
Aggregation.project("userId","login","firstName","lastName","email","deactivateFlag","createdOn")
);