Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
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 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda