您的位置:首页 > 数据库 > Mongodb

mongodb聚合统计

2014-03-24 11:50 337 查看
> db.salary.find()
{ "_id" : ObjectId("532be543edb9e06960e550b3"), "name" : "tom", "salary" : 98 }
{ "_id" : ObjectId("532be54eedb9e06960e550b4"), "name" : "tom", "salary" : 96 }
{ "_id" : ObjectId("532be559edb9e06960e550b5"), "name" : "jerry", "salary" : 86 }
{ "_id" : ObjectId("532be55eedb9e06960e550b6"), "name" : "jerry", "salary" : 88 }

db.salary.aggregate(
{$match:{name:"tom"}},{$group:{_id:"$name",total:{$sum:"$salary"}}}
);
统计name等于tom的人的salary
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: