So i have an array of object from mongodb query like below,its contained the value from $agg:
[
{
"_id": "17000691",
"latestAnswer": [
{
"title": "Test",
"date": "2022-11-16",
"position": "Foreman",
"department": "Production",
"username": "17000691"
}
]
},
{
"_id": "MT220047",
"latestAnswer": [
{
"title": "Test",
"date": "2022-11-15",
"position": "Management Trainee",
"department": "Logistic",
"username": "MT220047"
},
{
"title": "Test",
"date": "2022-11-16",
"position": "Management Trainee",
"department": "Logistic",
"username": "MT220047"
},
{
"title": "Test",
"date": "2022-11-16",
"position": "Management Trainee",
"department": "Logistic",
"username": "MT220047"
},
{
"title": "Untitled Form1",
"date": "2022-11-16",
"position": "Management Trainee",
"department": "Logistic",
"username": "MT220047"
}
]
}
]
is there a possible way to group the data base on date, title and username into this?
[
{
"username": "MT220047",
"title": "Test",
"position": "Management Trainee",
"department": "Logistic",
"2022-11-15": 1,
"2022-11-16": 2
},
{
"username": MT220047,
"title": UntitledForm1,
"position": "Management Trainee",
"department": "Logistic",
"2022-11-16": 1
},
{
"username": 17000691,
"title": Test,
"position": "Foreman",
"department": "Production",
"2022-11-16": 1,
}
]
any help on this will be useful for mee... thanks.., it try to mapping it but seems little confused bout the logic to group it as i want