Database
db={Classes:[{"_id":ObjectId("5df58d45244a850d54b922c8"),"mentors":{"numOfMentors":NumberInt(1),"mentorList":[ObjectId("5c9ba636347bb645e0865283")]},"lessons":[{"_id":ObjectId("5db221be211d7b68ac8be618"),"mentorData":{"objective":"Ensuring students that making mistakes is normal and that it is a part of life","task":"Post a video explaining obstacles that you had to overcome as a programmer","dueDate":ISODate("2019-12-14T15:26:10.000Z")},"studentData":{"objective":"Learning that failures help you grow","task":"Post a video explaining obstacles that you have overcame","dueDate":ISODate("2020-01-14T22:26:10.000Z")},"title":"How to overcome obstacles","comments":[]}]}],users:[{"_id":ObjectId("5c9ba636347bb645e0865283"),"securityQuestions":{"isSetup":false},"corporation":ObjectId("5d83749fb57cc711487f1cc2"),"videos":[],"events":[],"name":"Jackie Uphill"}],"corporation":[{"_id":ObjectId("5d83749fb57cc711487f1cc2"),"name":"STEMuli Education"}]}
Query
db.Classes.aggregate([{$unwind:"$lessons"},{$addFields:{date:{$dateToString:{format:"%Y-%m-%d",date:"$lessons.studentData.dueDate"}}}},{$group:{_id:"$_id",lessons:{$push:"$lessons"},mentors:{$push:"$mentors.mentorList"}}},{$addFields:{mentors:{$reduce:{input:"$mentors",initialValue:[],in:{$setUnion:["$$value","$$this"]}}}}},{$lookup:{from:"users",let:{mentor_ids:"$mentors"},pipeline:[{$match:{$expr:{$in:["$_id","$$mentor_ids"]}}},{$lookup:{from:"corporation",localField:"corporation",foreignField:"_id",as:"corporation"}},{$unwind:"$corporation"},{$project:{name:1,"corporation.name":1}}],as:"mentors"}}])