我有一个简单的集合:
{
"_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 query that I have come up with is
db.alarm.group( {key: { serverName:true }, reduce: function(obj,prev) { prev.count++ }, initial: { count: 0 }});
另外,我已经在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"
}
]
然而,在MongoDB中,我需要等待13秒才能得到响应。而在SQL Server中,类似的查询仅需4秒即可返回结果,且无须索引支持。
是否有遗漏了什么呢?
谢谢您的耐心等待。