Có những ví dụ về điều này trên khắp tài liệu, Google và trang web này.
Một số tài liệu tham khảo:
- http://api.mongodb.org/python/current/ Ví dụ / Tổng hợp.html
- http://docs.mongodb.org/manual/reference/aggregation / group /
- http://docs.mongodb.org/manual/reference/aggregation / sum /
Và đối với một số mã:
self.db.aggregate(
# Lets find our records
{"$match":{"Time":{"$gte":100,"$lte":1000}}},
# Now lets group on the name counting how many grouped documents we have
{"$group":{"_id":"$name", "sum":{"$sum":1}}}
)