2017-08-25 50 views
0

我使用此查詢找到狀態(「isActive」:假)真或假還發現年齡取決於狀況最新統計總量MongoDB的總斷言:命令失敗

db.programmershelper.aggregate([{ 
    $match: { 
     "isActive": false 
    } 
}, { 
    $group: { 
     _id: "age", 
     total: { $count: "$amount" } 
    } 
}]) 

顯示此消息,以及 斷言:命令失敗:{ 「OK」:0, 「ERRMSG」: 「未知組操作員」$伯爵「, 」代碼「:15952, 」代號「: 」Location15952「 }

F ollowing錯誤

總失敗
[email protected]/mongo/shell/utils.js:25:13

+0

什麼是「年齡」在這裏?什麼是「金額」? – nullpointer

回答

1

您可以按照count, sum and average docsgroup找到你的每requriements精確解。

至於我從問題中瞭解的內容,您希望根據過濾器"isActive": false進行聚合,並根據最後一個總數計算年齡。

db.programmershelper.aggregate([{ 
    $match: { 
     "isActive": false 
    } 
}, { 
    $group: { 
     _id: "age", 
     count: { $sum: 1 } 
    } 
}])