Database

db={"idCollectionName":[{"_id":ObjectId("5e22854fe659c68e8e8bcfd7"),"id":1.0,"month":1.0,"count":1.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfd8"),"id":1.0,"month":2.0,"count":2.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfd9"),"id":1.0,"month":3.0,"count":3.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfda"),"id":2.0,"month":1.0,"count":1.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfdb"),"id":2.0,"month":2.0,"count":2.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfdc"),"id":2.0,"month":3.0,"count":3.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfdd"),"id":3.0,"month":1.0,"count":1.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfde"),"id":3.0,"month":2.0,"count":2.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfdf"),"id":3.0,"month":3.0,"count":3.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfe0"),"id":4.0,"month":1.0,"count":1.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfe1"),"id":4.0,"month":2.0,"count":2.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfe2"),"id":4.0,"month":3.0,"count":3.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfe3"),"id":5.0,"month":1.0,"count":1.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfe4"),"id":5.0,"month":2.0,"count":2.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfe5"),"id":5.0,"month":3.0,"count":3.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfe6"),"id":6.0,"month":1.0,"count":1.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfe7"),"id":6.0,"month":2.0,"count":2.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfe8"),"id":6.0,"month":3.0,"count":3.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfe9"),"id":7.0,"month":1.0,"count":1.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfea"),"id":7.0,"month":2.0,"count":2.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfeb"),"id":7.0,"month":3.0,"count":3.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfec"),"id":8.0,"month":1.0,"count":1.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfed"),"id":8.0,"month":2.0,"count":2.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfee"),"id":8.0,"month":3.0,"count":3.0},{"_id":ObjectId("5e22854fe659c68e8e8bcfef"),"id":9.0,"month":1.0,"count":1.0},{"_id":ObjectId("5e22854fe659c68e8e8bcff0"),"id":9.0,"month":2.0,"count":2.0},{"_id":ObjectId("5e22854fe659c68e8e8bcff1"),"id":9.0,"month":3.0,"count":3.0}],"divisionIdCollName":[{"_id":ObjectId("5e2285a6e659c68e8e8bcff2"),"divisionId":1.0,"id":[1.0,2.0,4.0,5.0]},{"_id":ObjectId("5e2285a6e659c68e8e8bcff3"),"divisionId":2.0,"id":[3.0,6.0,8.0,9.0]},{"_id":ObjectId("5e2285a6e659c68e8e8bcff4"),"divisionId":3.0,"id":[7.0,10.0,19.0]}]}

Query

db.divisionIdCollName.aggregate([{$lookup:{from:"idCollectionName",let:{ids:"$id"},pipeline:[{$match:{$expr:{$in:["$id","$$ids"]}}}],as:"data"}},{$unwind:{path:"$data",preserveNullAndEmptyArrays:true}},{$group:{_id:{divisionId:"$divisionId",month:"$data.month"},month:{$first:"$data.month"},count:{$sum:"$data.count"}}},{$addFields:{divisionId:"$_id.divisionId"}},{$project:{_id:0}}])

Result