Last active
April 28, 2020 02:02
-
-
Save thorizer/a6abb470dbdada35bf879266d94883e7 to your computer and use it in GitHub Desktop.
Group objects by multiple properties including nested properties and sump up their values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Input :************************************************************************************************************************************ | |
[ | |
{ | |
"commissioningDate": "2019-09-27", | |
"_product": { | |
"_id": "aaa", | |
"name": "Installation" | |
}, | |
"zones": [ | |
{ | |
"_zone": { | |
"_id": "KK", | |
"name": "Zone kk" | |
}, | |
"category": "category1", | |
"zone_quantity": 6 | |
}, | |
{ | |
"_zone": { | |
"_id": "BB", | |
"name": "Zone BB" | |
}, | |
"category": "category1", | |
"zone_quantity": 3 | |
} | |
], | |
"product_quantity": 3 | |
}, | |
{ | |
"commissioningDate": "2019-09-27", | |
"_product": { | |
"_id": "aaa", | |
"name": "Installation" | |
}, | |
"zones": [ | |
{ | |
"_zone": { | |
"_id": "KK", | |
"name": "Zone kk" | |
}, | |
"category": "category2", | |
"zone_quantity": 3 | |
} | |
], | |
"product_quantity": 2 | |
}, | |
{ | |
"commissioningDate": "2019-09-27", | |
"_product": { | |
"_id": "aaa", | |
"name": "Installation" | |
}, | |
"zones": [ | |
{ | |
"_zone": { | |
"_id": "KK", | |
"name": "Zone kk" | |
}, | |
"category": "category2", | |
"zone_quantity": 4 | |
} | |
], | |
"product_quantity": 5 | |
}, | |
{ | |
"commissioningDate": "2019-09-27", | |
"_product": { | |
"_id": "aaa", | |
"name": "Installation" | |
}, | |
"zones": [ | |
{ | |
"_zone": { | |
"_id": "CC", | |
"name": "Zone cc" | |
}, | |
"category": "category2", | |
"zone_quantity": 6 | |
} | |
], | |
"product_quantity": 1 | |
}, | |
{ | |
"commissioningDate": "2019-09-27", | |
"_product": { | |
"_id": "bbbb", | |
"name": "Installation" | |
}, | |
"zones": [ | |
{ | |
"_zone": { | |
"_id": "CC", | |
"name": "Zone cc" | |
}, | |
"category": "category2", | |
"zone_quantity": 8 | |
} | |
], | |
"product_quantity": 2 | |
}, | |
{ | |
"commissioningDate": "2019-09-26", | |
"_product": { | |
"_id": "bbbb", | |
"name": "Installation" | |
}, | |
"zones": [ | |
{ | |
"_zone": { | |
"_id": "CC", | |
"name": "Zone cc" | |
}, | |
"category": "category2", | |
"zone_quantity": 8 | |
} | |
], | |
"product_quantity": 2 | |
} | |
] | |
//output ************************************************************************************************************************************ | |
[ | |
{ | |
"commissioningDate": "2019-09-27", | |
"_product": { | |
"_id": "aaa", | |
"name": "Installation" | |
}, | |
"zones": [ | |
{ | |
"_zone": { | |
"_id": "KK", | |
"name": "Zone kk" | |
}, | |
"category": "category1", | |
"zone_quantity": 6 | |
},{ | |
"_zone": { | |
"_id": "KK", | |
"name": "Zone kk" | |
}, | |
"category": "category2", | |
"zone_quantity": 7 | |
},{ | |
"_zone": { | |
"_id": "CC", | |
"name": "Zone cc" | |
}, | |
"category": "category2", | |
"zone_quantity": 6 | |
},{ | |
"_zone": { | |
"_id": "BB", | |
"name": "Zone BB" | |
}, | |
"category": "category1", | |
"zone_quantity": 3 | |
} | |
], | |
"product_quantity": 11 | |
}, | |
{ | |
"commissioningDate": "2019-09-27", | |
"_product": { | |
"_id": "bbbb", | |
"name": "Installation" | |
}, | |
"zones": [ | |
{ | |
"_zone": { | |
"_id": "CC", | |
"name": "Zone cc" | |
}, | |
"category": "category2", | |
"zone_quantity": 8 | |
} | |
], | |
"product_quantity": 2 | |
}, | |
{ | |
"commissioningDate": "2019-09-26", | |
"_product": { | |
"_id": "bbbb", | |
"name": "Installation" | |
}, | |
"zones": [ | |
{ | |
"_zone": { | |
"_id": "CC", | |
"name": "Zone cc" | |
}, | |
"category": "category2", | |
"zone_quantity": 8 | |
} | |
], | |
"product_quantity": 2 | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment