[{
"_id": {
"year": 2017,
"month": 4
},
"Confirm": 0
}, {
"_id": {
"year": 2017,
"month": 4
},
"Expired": 25
}, {
"_id": {
"year": 2017,
"month": 4
},
"Pending": 390
}, {
"_id": {
"year": 2017,
"month": 5
},
"Pending": 1400
}]
The array above contain same value month and year. Generated from MongoDB Aggregate. And I want to merge them into a single object and preserve whatever keys and values they have.
Expected output:
[{
month: 4,
year: 2017,
Expired: 25,
Pending: 390
}, {
month: 5,
year: 2017,
Pending: 1400
}]
I prefer the fastest execution implementation. Underscorejs or native are welcome. Thanks