make aggregate_sum/average compatible with pymongo 3.x

This commit is contained in:
Stefan Wojcik 2015-06-08 13:46:19 -07:00
parent dd095279c8
commit 1233780265

View File

@ -1261,6 +1261,11 @@ class BaseQuerySet(object):
{ '$match': self._query },
{ '$group': { '_id': 'sum', 'total': { '$sum': '$' + field } } }
])
if IS_PYMONGO_3:
result = list(result)
if result:
return result[0]['total']
else:
if result['result']:
return result['result'][0]['total']
return 0
@ -1333,6 +1338,11 @@ class BaseQuerySet(object):
{ '$match': self._query },
{ '$group': { '_id': 'avg', 'total': { '$avg': '$' + field } } }
])
if IS_PYMONGO_3:
result = list(result)
if result:
return result[0]['total']
else:
if result['result']:
return result['result'][0]['total']
return 0