I am trying to manipulate a dataset to make it easy to display in mongoCharts. There are two sets of team_a and team_b, Each contains a set of playerId, score, rank and prize. I want to merge both arrays into one.
Sample Document:
{ team_a: { team_score: 94, team_name: "team_1", players: [ { id: "604f00d43776e45a448628f9", score: "33", rank: "1", prize: 15.4, }, { id: "60058dd9b88cc1a1e40f2f54", score: "31", rank: "2", prize: 15.4, }, { id: "60058dd9b88cc1a1e40f2f55", score: "30", rank: "3", prize: 15.4, } ], }, team_b: { team_score: 62, team_name: "team_2", players: [ { id: "602ce34a39c7496600940774", score: "32", rank: "1", }, { id: "60058db6b88cc1a1e40f2f4f", score: "30", rank: "2", }, ], }, }
And the desired output is:
{ team_a: [ { id: "604f00d43776e45a448628f9", score: "33", rank: "1", prize: 15.4, }, { id: "60058dd9b88cc1a1e40f2f54", score: "31", rank: "2", prize: 15.4, }, { id: “60058dd9b88cc1a1e40f2f55”, score: "30", rank: "3", prize: 15.4, } ], team_b: [ { id: "602ce34a39c7496600940774", score: "32", rank: "1", }, { id: "60058db6b88cc1a1e40f2f4f", score: "30", rank: "2", }, ], all_winners: [ { id: "604f00d43776e45a448628f9", score: "33", rank: "1", prize: 15.4, }, { id: "60058dd9b88cc1a1e40f2f54", score: "31", rank: "2", prize: 15.4, }, { id: "60058dd9b88cc1a1e40f2f55", score: "30", rank: "3", prize: 15.4, } { id: "60058dd9b88cc1a1e40f2f54", score: "31", rank: "4", }, { id: "60058db6b88cc1a1e40f2f4f", score: "30", rank: "5", }, ] }
Any guidance or pointers are gratefully received.
Thanks