def aggregate_post_types():
"""
counting the types of posts.
:return: list of dicts each one contain type name and counter
"""
pipeline = [
{"$group": {"_id": "$type", "count": {"$sum": 1}}},
{"$sort": SON([("count", -1), ("_id", -1)])}
]
return posts.aggregate(pipeline)
评论列表
文章目录