Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

62
Vistas
Insanely slow Mongodb group query

I'm trying to aggregate $sum between 2 dates stored as UTC strings (yyyy-mm-dd-hh). It takes 5+ seconds to get the results. My collection has 5 million+ docs.

      { 
          $match: {
            start: { 
              $gte: '2020-08-01-00',
              $lte: '2021-08-01-00'
            }
          }
        },
        {
          $group: {
            _id: { 
                symbol: '$symbol'
            },
            unverifiedCount: {
                $sum: {
                    $cond: {
                        if: { $eq: ['$isVerified', false] }, then: '$count', else: 0
                    }
                }
            },
            verifiedCount: {
                $sum: {
                    $cond: {
                        if: { $eq: ['$isVerified', true]}, then: '$count', else: 0
                    }
                }
              }
          }
        }, {
          $sort: {
            unverifiedCount: -1
          }
        }

Tried using $toDateString but performance remained the same

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos