I’m trying to build an aggregation that updates the players document with the points that they receive from the games that they play.
Here is the game document
"_id": {
"$oid": "63d00ec0771f06853d860862"
},
"game_id": 1,
"winner": "player1",
"con_id": "I",
"map": "US",
"player_results": [
{
"player-id": "player1",
"totalMoney": 15,
"totalPoints": 3
},
{
"player-id": "player2",
"totalMoney": 15,
"totalPoints": 3,
"winner": false
}
]
},
{
"_id": {
"$oid": "63d00ec4dfdd8cb0e496422f"
},
"game_id": 2,
"winner": "",
"con_id": "I",
"map": "EU",
"player_results": [
{
"player-id": "player1",
"totalMoney": 25,
"totalPoints": 3,
"winner": true
},
{
"player-id": "player2",
"totalMoney": 15,
"totalPoints": 2,
"winner": false
}
]
},
Here is the player documents in the same collection
{
"_id": {
"$oid": "63d01ae4b152a993335ef75e"
},
"player-id": "player1",
"totalMoney": 0,
"totalPoints": 0
}
So in the ideal scenario it would update the player1 document to have totalPoints of 6 and totalMoney of 40.