Database

db={"department":[{"_id":ObjectId("615851c162a012f82cc5bdf6"),"name":"abc","employee_id":[ObjectId("615852d062a012f82cc5d54d"),ObjectId("6158530462a012f82cc5d9c8"),ObjectId("6158530462a012f82cc8e1b9")]}],"employee":[{"_id":ObjectId("615852d062a012f82cc5d54d"),"name":"john","salary":12345},{"_id":ObjectId("6158530462a012f82cc5d9c8"),"name":"smith","salary":999},{"_id":ObjectId("6158530462a012f82cc8e1b9"),"name":"Alex","salary":99999}]}

Query

db.department.aggregate([{"$match":{"name":"abc"}},{"$lookup":{"from":"employee",let:{eid:"$employee_id",departmentName:"$name"},pipeline:[{"$match":{$expr:{$in:["$_id","$$eid"]}}},{$sort:{salary:-1}},{"$limit":2},{"$addFields":{"department":"$$departmentName"}}],"as":"employees"}},{"$unwind":{path:"$employees"}},{"$replaceRoot":{"newRoot":"$employees"}}])

Result