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" }
the collection will have about two million such documents. I am trying to group by server name and get the number of all server names. Sounds easy in terms of RDBMS queries.
The query that I have come up with is db.alarm.group( {key: { serverName:true }, reduce: function(obj,prev) { prev.count++ }, initial: { count: 0 }});
In addition, I added an index to 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 get a response in mongodb after 13 seconds. whereas in the sql server a similar query is returned back within 4 seconds, which is also without an index.
Is there something I am missing?
Thanks pending.
mongodb
nkare Aug 21 '12 at 20:31 2012-08-21 20:31
source share