07-31-2023, 09:23 AM
I have collection in MongoDB:
{ "_id" : ObjectId("4d2407265ff08824e3000001"), "subida" : 3.95 }
{ "_id" : ObjectId("4d2551b4ae9fa739640df821"), "subida" : 6.03 }
{ "_id" : ObjectId("4d255b115ff08821c2000001"), "subida" : 5.53 }
{ "_id" : ObjectId("4d25e8d55ff08814f8000001"), "subida" : 1.96 }
How I can sum the value of a key, e.g., `"subida"`, across all documents? With the documents above, I should receive something along the lines of:
{ "subida" : 17.47 }
{ "_id" : ObjectId("4d2407265ff08824e3000001"), "subida" : 3.95 }
{ "_id" : ObjectId("4d2551b4ae9fa739640df821"), "subida" : 6.03 }
{ "_id" : ObjectId("4d255b115ff08821c2000001"), "subida" : 5.53 }
{ "_id" : ObjectId("4d25e8d55ff08814f8000001"), "subida" : 1.96 }
How I can sum the value of a key, e.g., `"subida"`, across all documents? With the documents above, I should receive something along the lines of:
{ "subida" : 17.47 }