Mongo Playground

Configuration

[{"name":"Spidey One way home","release_year":"2021","rating":9,"starring":["Tom Hanks","Tom Holland","Mark Zucks","Samy"],"runtime":120,"totalReviews":2000,"director":"Jon What"},{"name":"The Arrival of a Train","release_year":"1896","rating":6,"starring":["Shawn Ching","Looker Blindspot","Tom Hanks"],"runtime":115,"totalReviews":720,"director":"Ricky"},{"name":"Lost persuit of adventure","release_year":"2005","rating":7.1,"starring":["Jimmy simmon","Catarina"],"runtime":150,"totalReviews":823,"director":"Ricky"},{"name":"Jungle Warrior","release_year":"2016","rating":5.9,"starring":["Stormer","Carmony","Tom Hanks"],"runtime":150,"totalReviews":1368,"director":"Whim Wailer"},{"name":"The Last of the us all","release_year":"2005","rating":8.5,"starring":["Samy","George wise","Pennywise"],"runtime":120,"totalReviews":1800,"director":"Jon What"}]

Query

db.collection.aggregate([{$group:{_id:"$release_year",totalRuntime:{"$sum":"$runtime"}}},{"$sort":{"totalRuntime":-1}}])

Result