Database
db={"categories":[{_id:3276438964823,name:"Category 1",companyId:12345}],"exams":[{_id:482348327,categoryId:3276438964823,name:"Computer",companyId:12345},{_id:482343338327,categoryId:3276438964823,name:"Computer",companyId:12345}],"results":[{_id:3233980,exam_id:482348327}]}
Query
db.categories.aggregate([{$lookup:{from:"exams",localField:"_id",foreignField:"categoryId",as:"examsCount"}},{$lookup:{from:"results",localField:"examsCount._id",foreignField:"exam_id",as:"doneExams"}},{$addFields:{examsCount:{$size:"$examsCount"},doneExams:{$size:"$doneExams"}}}])