Database
[{"stock":"Stock1","value":12,"month":1,"year":2019},{"stock":"Stock1","value":13,"month":2,"year":2019},{"stock":"Stock1","value":14,"month":1,"year":2020},{"stock":"Stock1","value":15,"month":2,"year":2020},{"stock":"Stock2","value":6,"month":1,"year":2019},{"stock":"Stock2","value":5,"month":2,"year":2019}]
Query
db.collection.aggregate({"$sort":{"year":-1}},{$group:{_id:{"stock":"$stock","year":"$year"},stockYearItems:{$push:"$$ROOT"}}},{$group:{_id:"$_id.stock",items:{$first:"$$ROOT"}}},{$unwind:"$items.stockYearItems"},{"$replaceRoot":{"newRoot":"$items.stockYearItems"}})