只需使用带有 *
pipe = [{'$group': {'_id': None, 'total': {'$sum': '$goals'}}}]
db.goals.aggregate(pipeline=pipe)
Out[8]: {u'ok': 1.0, u'result': [{u'_id': None, u'total': 12.0}]}
MongoDB聚合/组/总和查询转换为pymongo查询
只需使用带有 *
pipe = [{'$group': {'_id': None, 'total': {'$sum': '$goals'}}}]
db.goals.aggregate(pipeline=pipe)
Out[8]: {u'ok': 1.0, u'result': [{u'_id': None, u'total': 12.0}]}