Database

[{"studentid":"stu-1234","dept":"geog","Carddetails":{"LastSwipeTimestamp":"2021-11-25T10:50:00.5230694Z"}},{"studentid":"stu-1234","dept":"geog","Carddetails":{"LastSwipeTimestamp":"2021-11-25T11:50:00.5230694Z"}},{"studentid":"stu-abc","dept":"geog","Carddetails":{"LastSwipeTimestamp":"2021-11-25T09:15:00.5230694Z"}},{"studentid":"stu-abc","dept":"geog","Carddetails":{"LastSwipeTimestamp":"2021-11-25T11:30:00.5230694Z"}}]

Query

db.collection.aggregate([{$match:{"studentid":{"$in":["stu-abc","stu-1234"]},"dept":"geog"}},{$sort:{"Carddetails.LastSwipeTimestamp":-1}},{$group:{"_id":{"studentid":"$studentid","dept":"$dept"},"Carddetails":{$first:"$Carddetails"}}},{$project:{_id:0,"studentid":"$_id.studentid","dept":"$_id.dept","Carddetails":"$Carddetails"}}])

Result