I have the following aggregation pipeline, but I would like to have the hcapPlaying
attribute in the final outputted document as a named attribute.
[{$match: {
'compId': ObjectId('6056fe9cb36a4f58ff44055d')
}}, {$group: {
_id: [
'$playerName',
'$playerId',
'$hcapPlaying'
],
'score': {
'$sum': '$computedScore'
},
'thru': {
'$sum': '$computedThru'
}
}}, {$addFields: {
'hcap': '$_id.hcapPlaying'
}}, {$sort: {
'score': 1
}}]
But in the syntax above, the new hcap
attribute is an empty Array.