How can I compute the aggregate of the following metrics without knowing all the metrics before hand? Can I accomplish this using the aggregate framework or MapReduce?
[
{
player_id: '123',
timestamp: <sometime>,
metrics: {
points_per_game: 1,
rebounds_per_game: 2,
assist_per_game: 3,
}
},
{
player_id: '123',
timestamp: <sometime>,
metrics: {
points_per_game: 1,
rebounds_per_game: 2,
}
},
{
player_id: '345',
timestamp: <sometime>,
metrics: {
points_per_game: 1,
rebounds_per_game: 2,
point_in_the_paint_per_game: 2
}
}
]
I would like to have the following result
[
{
player_id: '123',
metrics: {
points_per_game: 2,
rebounds_per_game: 4,
assist_per_game: 3,
}
},
{
player_id: '345',
metrics: {
points_per_game: 1,
rebounds_per_game: 2,
point_in_the_paint_per_game: 2
}
}
]
I cannot do something like the following since it would require me to know every metrics:
db.stats.aggregate([
{$group: {
_id: {player: "$player_id"},
points_per_game: { $sum: "$metrics.points_per_game"}
...
])