我从小就用MySQL,现在因为种种原因必须转向MongoDB。
我写了一个日志,将每个php错误保存在MongoDB集合中。读取错误并不是问题,使用简单的find()非常容易,并且可以使用php数组来获取数据,这一点很棒。
现在我想要一些关于错误的统计数据。我的集合看起来像:
{
"_id": ObjectId("51af10ca0e5e723c0a000000"),
"Errors": {
"2048": {
"0": {
"Message": "Declaration of ADODB_mysqli::MetaIndexes() should be compatible with ADOConnection::MetaIndexes($table, $primary = false, $owner = false)",
"File": "File.php",
"Line": NumberInt(29),
"Time": NumberInt(1370427591)
}
},
"2": {
"0": {
"Message": "Error",
"File": "File.php",
"Line": NumberInt(29),
"Time": NumberInt(1370427591)
},
"1": {
"Message": "Error",
"File": "File.php",
"Line": NumberInt(29),
"Time": NumberInt(1370427591)
}
},
"8": {
"0": {
"Message": "Undefined index: PluginLastAdded",
"File": "File.php",
"Line": NumberInt(36),
"Time": NumberInt(1370427594)
},
"1": {
"Message": "Undefined index: PluginLastAdded",
"File": "File.php",
"Line": NumberInt(36),
"Time": NumberInt(1370427594)
}
}
}
}
现在我想知道此条目中每个错误发生的频率。最好能将其分成2048、2和8的区别列表,然后统计每个错误的数量。
是否可以使用MongoDB的聚合来完成这项工作,而不需要太多的php代码?
任何帮助都将是极好的。在我看来,MongoDB与MySQL完全不同,转换相当困难。