> db.users.find().pretty()
{
"_id" : ObjectId("5b79047abd2b073cdefed380"),
"name" : "marry",
"age" : 23,
"status" : "A",
"amount" : 250,
"coust_id" : "A123"
}
{
"_id" : ObjectId("5b790472bd2b073cdefed37f"),
"age" : 18,
"amount" : 200,
"coust_id" : "A123",
"name" : "tom",
"status" : "A"
}
{
"_id" : ObjectId("5b790955bd2b073cdefed381"),
"name" : "joe",
"age" : 18,
"amount" : 200,
"coust_id" : "B123",
"status" : "B"
}
{
"_id" : ObjectId("5b790981bd2b073cdefed382"),
"name" : "lee",
"age" : 20,
"amount" : 100,
"coust_id" : "A122",
"status" : "A"
}
copy
> db.users.aggregate([{$match:{status:'A'}},{$group:{'_id':"$coust_id", total:{$sum:"$amount"}}}])
{
"result" : [
{
"_id" : "A122",
"total" : 100
},
{
"_id" : "A123",
"total" : 450
}
],
"ok" : 1
}
copy
学习时间 520分钟
操作时间 120分钟
按键次数 7278次
实验次数 4次
报告字数 798字
是否完成 完成