我从小就使用 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,然后是每个错误的计数。
没有太多 php 代码但使用 MongoDB 的聚合是否可能?
任何帮助都会很棒,在我看来,MongoDB 与 MySQL 有 180° 的不同,而且切换非常困难。