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

55
Views
mongodb aggregate on huge dataset

i have a mongodb db with more than 100 millions documents. i want to do aggregation so i can give statistics on documents. my document look like :

{
    "categ": "categ_4", 
    "code": 200, 
    "date": "01/01/2017", 
    "host": "www.myhost.com", 
    "hour": "19", 
    "http_ver": "HTTP/1.1", 
    "idate": 20170101, 
    "length": 21, 
    "protocol": "https", 
    "remote_ip": "111.22.333.44", 
    "resp_time": 0, 
    "time": "19:53:15", 
    "url": "my_url", 
}

when aggregating, i perform a query like this in my shell :

db.data.aggregate([{"$match": {"code":200}}, {"$group": {_id : "$code", total : {"$sum" : 1}}},{"$sort" : {_id: 1}}])

the problem is that it takes a very long time to compute. this is too slow. is there any way to speed up this operation ? i tryed to create index on "code" field but with no success

db.data.createIndex({code:1})

what can I do to make aggregation faster ?

thank you

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Seems like your query is same as

db.data.count({"code":200})

you don't need aggregation for that. Try simple count (with index)

over 4 years ago · Santiago Trujillo Report
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!