Database
db={"student":[{_id:4,name:"tom"},{_id:5,name:"john"}],"meetup":[{_id:1,studentId:5,startTime:ISODate("2022-05-01")},{_id:2,studentId:4,startTime:ISODate("2022-01-05")},{_id:3,studentId:4,startTime:ISODate("2025-01-05")}]}
Query
db.student.aggregate([{"$lookup":{"from":"meetup","let":{studentId:"$_id"},"pipeline":[{$match:{$expr:{$and:[{$eq:["$$studentId","$studentId"],},{$gt:["$startTime","$$NOW"],}]}}},{$project:{_id:1,startTime:1,}}],"as":"meetup"}},{$sort:{"meetup.startTime":1}}])