如何求和字段的值?
How to sum the values of fields?
我有这样的结构
{
"actionName": "add_new_paint_layer",
"countUse": 1,
"sources": "smth"
},
{
"actionName": "clear",
"countUse": 1,
"sources": "smth"
},
{
"actionName": "clear",
"countUse": 5,
"sources": "smth"
},
如何对 actionName "clear" 求和 "countUse"?
db.collection.aggregate([
{$match:
{'actionName': 'clear'},
{$group:
{_id: "$actionName",
total_count:{ $sum: "$countUse"}}}
])
我有这样的结构
{
"actionName": "add_new_paint_layer",
"countUse": 1,
"sources": "smth"
},
{
"actionName": "clear",
"countUse": 1,
"sources": "smth"
},
{
"actionName": "clear",
"countUse": 5,
"sources": "smth"
},
如何对 actionName "clear" 求和 "countUse"?
db.collection.aggregate([
{$match:
{'actionName': 'clear'},
{$group:
{_id: "$actionName",
total_count:{ $sum: "$countUse"}}}
])