다음은 내 원주민 MongoDB 쿼리이며 아래는 SpringData Mongo API에 해당합니다. SpringData Mongo API의 $ 프로젝트에서 $ map을 사용하는 것에 대해 고심하고 있습니다. 당신은 $map
집계 아래 시도 할 수 있습니다 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} }
])
봄 쿼리
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")
);
의 가능한 복제 http://stackoverflow.com/questions/41847249/filter-array-in-sub-document-array-field-in -spring-framework) – Veeram
정보 주셔서 감사합니다. 하지만 API를 이해하려면 좀 더 도움이 필요합니다. 내 요구 사항이 다릅니다. ("created_by"). as ("u"). Aggregation.project ("userId", "login", "firstName", "lastName", "email", "deactivateFlag", "createdOn") \t \t .and (mapItemsOf). \t \t \t \t ??? \t \t)). ("createdBy")로 – karmaker