我正在学习MongoDB并尝试实现与聚合相关的命令。
收藏如下:
{ "_id" : ObjectId("5bbc185f132cf4170a2f5fd3"), "custID" : "A123", "Amount" : 500, "status" : "A" }
{ "_id" : ObjectId("5bbc187d132cf4170a2f5fd4"), "custID" : "A123", "Amount" : 250, "status" : "A" }
{ "_id" : ObjectId("5bbc188d132cf4170a2f5fd5"), "custID" : "B212", "Amount" : 200, "status" : "A" }
第一个查询是
Find out total amount for individual customer ID having status âAâ
从这里我编码了:
db.emp.aggregate([{$match:{'status':'A'}},{'totalAmount':{$sum:'$Amount'}}])
但是得到这个错误:
"errmsg" : "Unrecognized pipeline stage name: 'totalAmount'"
我哪里出错了?