1. 程式人生 > >重新學習mongodb:聚合

重新學習mongodb:聚合

聚合框架概覽:

db.reviews.aggregate([{$group:{_id:'$product_id',count:{$sum:1}}}]);
product = db.products.findOne({'slug':'wheelbarrow-9092'});

ratingSummary = db.review.aggregate([
{$match:{'product_id':product['_id']}},
{$group:{_id:'$product_id',
average:{$avg:'$rating'},
count:{$sum:1}}}
])

$project

$group:

$match、$sort、$skip、$limit

$out