So I have my pymongo cursor and very plain loop to get total sum. I need to fetch that value, also I am very new to Mongo and my approach might be not the best practice.
cursor = db.reportsColl.aggregate([
{"$unwind": "$conditions"},
{"$group": {"_id": "$_id", "sum": { "$sum": 1}}}])
x = 0
for result in cursor:
x+= result['sum']
print(x)
I am trying to use lambda expression here, but I feel that I've kinda lost.
total = [(lambda x: x+result['sum'])(x) for _ in cursor]
Any ideas?
total = sum(result['sum'] for result in cursor)