I have a simple collection :
{
"_id" : ObjectId("5033cc15f31e20b76ca842c8"),
"_class" : "com.pandu.model.alarm.Alarm",
"serverName" : "CDCAWR009 Integration Service",
"serverAddress" : "cdcawr009.na.convergys.com",
"triggered" : ISODate("2012-01-28T05:09:03Z"),
"componentName" : "IntegrationService",
"summary" : "A device which is configured to be recorded is not being recorded.",
"details" : "Extension<153; 40049> on CDCAWR009 is currently not being recorded
properly; recording requested for the following reasons: ",
"priority" : "Major"
}
there will be around couple of millions of such documents in the collection. I am trying to group by the server name and get a count of all server name. Sounds simple from RDBMS query point of view.
The query that I have come up with is
db.alarm.group( {key: { serverName:true }, reduce: function(obj,prev) { prev.count++ }, initial: { count: 0 }});
Also, I have added an index on serverName.
> db.alarm.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "test.alarm",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"serverName" : 1
},
"ns" : "test.alarm",
"name" : "serverName_1"
}
]
However, i am getting a response in mongodb after 13 seconds. whereas in sql server, similar query returns back within 4 seconds that too without an index.
Is there anything I am missing?
Thanks in anticipation.