Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!