나는 "Feedback"
컬렉션에 저장된 데이터를 가진 NodeJS/MongoDB 앱을 가지고 있습니다. 데이터는 다음과 같습니다.몽구스 : 집계 및 집계
[
{
"__v": 0,
"_id": "57d6b2d09f46ca14440ac14e",
"customerFeedback": [
{
"_id": "57d6b2d09f46ca14440ac14f",
"answer": [
{
"_id": "57d6b2d09f46ca14440ac150",
"answerValue": "cat",
"answerWeight": 0
}
],
"question": "What is your favourite thing about this shop?",
"questionId": "57d65edc0132461120fa0afd"
},
{
"_id": "57d6b2d09f46ca14440ac151",
"answer": [
{
"_id": "57d6b2d09f46ca14440ac152",
"answerValue": "Okay",
"answerWeight": 0
}
],
"question": "How was your experience today?",
"questionId": "57d69ef6dbb25611e46e6bc9"
}
],
"shopId": "SH0001",
"feedbackCreatedOn": "2016-09-12T13:51:12.703Z",
"questionsForDay": "2016-09-12T00:00:00Z"
},
{
"__v": 0,
"_id": "57d6b3389f46ca14440ac157",
"customerFeedback": [
{
"_id": "57d6b3389f46ca14440ac158",
"answer": [
{
"_id": "57d6b3389f46ca14440ac159",
"answerValue": "cat",
"answerWeight": 0
}
],
"question": "What is your favourite thing about this shop?",
"questionId": "57d65edc0132461120fa0afd"
},
{
"_id": "57d6b3389f46ca14440ac15a",
"answer": [
{
"_id": "57d6b3389f46ca14440ac15b",
"answerValue": "Very Good",
"answerWeight": 0
}
],
"question": "How was your experience today?",
"questionId": "57d69ef6dbb25611e46e6bc9"
},
{
"_id": "57d6b3389f46ca14440ac15c",
"answer": [
{
"_id": "57d6b3389f46ca14440ac15d",
"answerValue": "Cost",
"answerWeight": 0
}
],
"question": "What would you like us to improve on?",
"questionId": "57d6b32d9f46ca14440ac153"
}
],
"shopId": "SH0001",
"feedbackCreatedOn": "2016-09-12T13:52:56.939Z",
"questionsForDay": "2016-09-12T00:00:00Z"
},
{
"__v": 0,
"_id": "57d6c8eb97157f10a4e5c2e7",
"customerFeedback": [
{
"_id": "57d6c8eb97157f10a4e5c2e8",
"answer": [
{
"_id": "57d6c8eb97157f10a4e5c2ea",
"answerValue": "Customer Experience",
"answerWeight": 0
},
{
"_id": "57d6c8eb97157f10a4e5c2e9",
"answerValue": "Others",
"answerWeight": 0
}
],
"question": "What would you like us to improve on?",
"questionId": "57d6b7d99ee61e47f01e5334"
}
],
"shopId": "SH0003",
"feedbackCreatedOn": "2016-09-12T15:25:31.724Z",
"questionsForDay": "2016-09-12T00:00:00Z"
}
]
결과 배열에는 이러한 항목이 많이 있지만 위의 데이터는이를 설명하는 데 사용됩니다.
제 질문은 주어진 shopId
과 questionId
에 대해 각 개인이 answerValue
번 발생하는 횟수를 계산하려고합니다. 어떻게해야합니까?
나는
db.Feedback.find({shopId:"SH0001",'customerFeedback.questionId':"57d65edc0132461120fa0afd"})
(예를 들어)로 찾기 방법을 사용하여 필요한 데이터 세트까지 결과를 필터링 할 수 있어요하지만 내가 원하는 형식으로 데이터를 집계하는 방법을 모르겠어요.
안녕하세요! 답장을 보내 주셔서 감사합니다. QuestionId로 결과를 필터링하고 싶습니다. 파이프 라인에서 $ match 절을 어디에 추가해야합니까? 나는 그 일을 시도했지만, 나는 그다지 성공하지 못했습니다. questionId는 CustomerFeedback 내부에 중첩되어 있으며 저에게 충격을줍니다. –
내 업데이트보기 - 도움이 되시길 바랍니다. – DAXaholic
답장을 보내 주셔서 감사합니다. DB 셸에서 작업 할 수 있습니다. 그러나 난 내 애플 리케이션에서 그것을 사용하여 어려움에 직면하고있어. 설명 할 질문을 업데이트했습니다. –