首页 > 代码库 > MongoDB Aggregate
MongoDB Aggregate
1. sum
{ "_id" : ObjectId("50b1aa983b3d0043b51b2c52"), "name" : "Nexus 7", "category" : "Tablets", "manufacturer" : "Google", "price" : 199}
select manufacturer,count(*) from xx
group by manufacturer
db.products.aggregate([ {$group: { _id:"$manufacturer", num_products:{$sum:1} } }])
result
{ "_id" : "Amazon", "num_products" : 2 }{ "_id" : "Sony", "num_products" : 1 }{ "_id" : "Samsung", "num_products" : 2{ "_id" : "Google", "num_products" : 1 }{ "_id" : "Apple", "num_products" : 4 }
MongoDB Aggregate
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。