• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

131
Views
Javascript aggregate with multiple matches

I am trying to create a aggregate pipeline with multiple matches, but not sure how to go about it?!?

Here is what I am trying:

const pipeline = [
  { match: { oomId: oomId, holes: 0, collectPutts: true } },
  { group: { 
    objectId: '$userId',
    puttsPlayed: { $sum: 1 },
    puts: {$sum: '$puts'},
    gir: {$sum: '$gir'},
    girHcp: {$sum: '$girHcp'}
  } },
  { match: { oomId: oomId, holes: 0, collectHits: true } },
  { group: { 
    objectId: '$userId',
    hits: {$sum: '$hit'},
    holesHit: {$sum: '$holesToHit'}
  } },
  { match: { oomId: oomId, holes: 0 },
  { group: { 
    objectId: '$userId',
    totalPlayed: { $sum: 1 },
    points: {$sum: '$points'},
    strokes: {$sum: '$strokes'}
  } },
  { project:{ 
      played: '$totalPlayed',
      puttsPlayed: '$puttsPlayed',
      puts: {$divide: ['$puts', '$puttsPlayed']},
      gir: {$divide: ['$gir', '$puttsPlayed']},
      girHcp: {$divide: ['$girHcp', '$puttsPlayed']},
      hits: '$hits',
      holesHit: '$holesHit',
      hitsPercentage: {
        $multiply: [
          { $divide: [ "$hits", "$holesHit" ] },
          100
        ]
      },
      points: {$divide: ['$points', '$totalPlayed']},
      strokes: {$divide: ['$strokes', '$totalPlayed']}
  }}
];

I am getting this error: Unexpected token '{'

Not sure where the error is, and is it even possible to do what I am trying to do? or should I user 3 different pipelines?

Any help is appreciated... New to aggregate :-/

about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You didn't close the brackets after 3rd $match stage. So, instead of this:

{ match: { oomId: oomId, holes: 0 },

Do this:

{ match: { oomId: oomId, holes: 0 } },
about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error