Database

[{name:"Example 1",year:"2012",},{name:"Example 2",year:"2012",},{name:"Example 3",year:"2013",},{name:"Example 4",year:"2014",}]

Query

db.collection.aggregate([{$group:{_id:"$year",sum:{$sum:1}}},{$setWindowFields:{sortBy:{_id:-1},output:{sum:{$sum:"$sum",window:{documents:["unbounded","current"]}}}}}])

Result