Here is an example of what the sample documents look like
{
userId: 1,
totalGames: 10,
winStats: 4,
lostStats: 6,
g1Stats: {
totalGames: 4,
winStats: 1,
lostStats: 3,
},
g2Stats: {
totalGames: 5,
winStats: 2,
lostStats: 3,
},
g3Stats: {
totalGames: 1,
winStats: 1,
lostStats: 0,
}
}
The data will be returned in this format
{
userId
totalGames
winStats
lostStats
}
If the gameType parameter includes [g1, g2], the result will be
{
userId: 1,
totalGames: 9,
winStats: 3,
lostStats: 6
}
which is the sum of g1Stats and g2Stats
If the gameType is empty, the query should return
{
userId: 1,
totalGames: 10,
winStats: 4,
lostStats: 6
}
Could someone assist me with constructing this query? Please note: Sorting operations are being performed on these fields which is why this specific format is used.