Reputation: 860
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
Upvotes: 2
Views: 1946
Reputation: 236218
Seems like your query is same as
db.data.count({"code":200})
you don't need aggregation for that. Try simple count (with index)
Upvotes: 2