Der er eksempler på dette overalt i dokumentationen, Google og denne side.
Nogle referencer:
- http://api.mongodb.org/python/current/ examples/aggregation.html
- http://docs.mongodb.org/manual/reference/aggregation /gruppe/
- http://docs.mongodb.org/manual/reference/aggregation /sum/
Og for noget kode:
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}}}
)