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:
{
_id: "6138669dde7a271290906e25",
team_a: {
team_score: 64,
players: [
{
id: "604f00d43776e45a448628f9",
score: "33",
rank: "1",
prize: 15.4,
},
{
id: "60058dd9b88cc1a1e40f2f54",
score: "31",
rank: "2",
prize: 15.4,
},
],
team_name: "team_1",
},
team_b: {
team_score: 62,
players: [
{
id: "602ce34a39c7496600940774",
score: "32",
rank: "1",
},
{
id: "60058db6b88cc1a1e40f2f4f",
score: "30",
rank: "2",
},
],
team_name: "team_2",
},
prize_pool: 30.8,
cut: 4,
tax: 5.2,
live_players: "4",
completed: true,
name: "match",
entry_money: "10",
expiration_time: "9/8/2021 12:33:06",
}
And desired output is:
all_winners: [
{
id: "604f00d43776e45a448628f9",
score: "33",
rank: "1",
},
{
id: "602ce34a39c7496600940774",
score: "32",
rank: "2",
},
{
id: "60058dd9b88cc1a1e40f2f54",
score: "31",
rank: "3",
},
{
id: "60058db6b88cc1a1e40f2f4f",
score: "30",
rank: "4",
},
],
Any guidance or pointers are gratefully received.
Thanks