Database

[{"_id":"fffdb22b-912d-4166-909b-7d0fe790ba2a","companyVendorId":"1001","date":ISODate("2019-01-02T05:30:00.000+05:30"),"amount":100},{"_id":"fff94874-27af-4a39-ae59-3a46b8c7f573","companyVendorId":"1002","date":ISODate("2019-01-25T05:30:00.000+05:30"),"amount":200},{"_id":"fff94874-27af-4a39-ae59-3a46b8c7f575","companyVendorId":"1002","date":ISODate("2019-01-29T05:30:00.000+05:30"),"amount":200},{"_id":"fff68faf-2f11-480f-83d2-bfcb45b12d5b","companyVendorId":"1004","date":ISODate("2019-01-12T05:30:00.000+05:30"),"amount":500},{"_id":"fff4dfaa-46cd-48e3-a871-1f086a2c5438","companyVendorId":"1005","date":ISODate("2019-02-13T05:30:00.000+05:30"),"amount":600},{"_id":"fff18ff2-015e-4ddc-81f2-a12ab3503d05","companyVendorId":"1006","date":ISODate("2019-02-08T05:30:00.000+05:30"),"amount":700},{"_id":"ffeb16cd-ae1b-4c1e-aa93-d64347b5ff33","companyVendorId":"1007","date":ISODate("2019-02-18T05:30:00.000+05:30"),"amount":800}]

Query

db.collection.aggregate([{"$match":{"date":{"$gte":ISODate("2019-01-01T00:00:00Z"),"$lte":ISODate("2019-12-31T23:59:59Z")}}},{$addFields:{month:{$month:"$date"}}},{$group:{_id:{vendor:"$companyVendorId",month:"$month"},amount:{$sum:"$amount"}}},{$sort:{amount:-1}},{$group:{_id:"$_id.month",top:{$push:{companyVendorId:"$_id.vendor",amount:"$amount",month:"$_id.month"}}}},{$project:{top:{$slice:["$top",2]}}},{$unwind:"$top"},{$replaceRoot:{newRoot:"$top"}},{$sort:{month:1,amount:-1}}])

Result