pipeline = [{'$match': options}, {'$group': {'_id': groupby, 'count': {
    '$sum': 1}}}, {'$group': {'_id': None, 'total': {'$sum': 1}, 'details':
    {'$push': {'groupby': '$_id', 'count': '$count'}}}}]
list(db.collection.aggregate(pipeline))
How to count pymongo aggregation cursor without iterating