2
我有以下的收集和:MongoDB的順序由上一個子集
error_reports
[
{
"_id":{
"$oid":"5184de1261"
},
"date":"29/04/2013",
"errors":[
{
"_id":"10",
"failures":2,
"alerts":1,
},
{
"_id":"11",
"failures":7,
"alerts":4,
}
]
},
{
"_id":{
"$oid":"5184de1262"
},
"date":"30/04/2013",
"errors":[
{
"_id":"15",
"failures":3,
"alerts":2,
},
{
"_id":"16",
"failures":9,
"alerts":1,
}
]
}
]
是否有可能通過檢索降序排序的失敗與失誤和警報和文件清單?我是新來的MongoDB,我已經2天尋找,但我無法弄清楚什麼是正確的查詢......
我想是這樣的:
db.error_reports.aggregate(
{ $sort : { failures: -1} },
{ $group:
{ _id: "$_id",
failures: { "$sum": "$errors.failures" }
}
}
);
但事與願違工作中,我認爲這是因爲$sum
:$errors.failures
的事情,我想總結的day_hours
子集合的每一個項目這個屬性,但我不知道在查詢中做到這一點...
非常感謝你,這正是我需要的。我不知道有這樣一個運營商。 – Sanduckhan