I am trying to figure out how to calculate a golf leaderboard using javascript and aggregate, but am having some issues.
Here is what I am trying to do:
const pipeline = [
{ match: { oomId: oomId, holes: 0 } },
{ group: {
objectId: '$userId',
played: { $sum: 1 },
puts: {$sum: '$puts'},
gir: {$sum: '$gir'},
girHcp: {$sum: '$girHcp'},
hits: {$sum: '$hit'},
holesHit: {$sum: '$holesToHit'},
points: {$sum: '$points'},
strokes: {$sum: '$strokes'}
} },
{ project:{
puts: {$divide: {'$puts', '$played'}},
gir: {$divide: {'$gir', '$played'}},
girHcp: {$divide: {'$girHcp', '$played'}}
}}
];
I get this error: Unexpected string
I might be looking at this the wrong way, but not sure how though… Hoping for help 🙂