Database
[{"key":1,"value":10},{"key":2,"value":11},{"key":3,"value":9},{"key":4,"value":12}]
Query
db.collection.aggregate([{$setWindowFields:{sortBy:{key:1},output:{prefix_max_val:{$max:"$value",window:{documents:["unbounded","current"]}}}}}])