我有这样的结构
{
"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"}}}
])