Database
db={"User":[{_id:ObjectId("5a934e000102030405000001")},{_id:ObjectId("5a934e000102030405000002")},{_id:ObjectId("5a934e000102030405000003")},{_id:ObjectId("5a934e000102030405000004")}],"Message":[{"from":ObjectId("5a934e000102030405000004"),"to":ObjectId("5a934e000102030405000001"),"acknowledged":false,date:"2020-04-17T18:26:29.353+00:00"},{"from":ObjectId("5a934e000102030405000001"),"to":ObjectId("5a934e000102030405000002"),"acknowledged":true,date:"2020-04-17T18:26:30.353+00:00"},{"from":ObjectId("5a934e000102030405000001"),"to":ObjectId("5a934e000102030405000003"),"acknowledged":false,date:"2020-04-17T18:26:31.353+00:00"},{"from":ObjectId("5a934e000102030405000002"),"to":ObjectId("5a934e000102030405000001"),"acknowledged":true,date:"2020-04-17T18:26:32.353+00:00"},{"from":ObjectId("5a934e000102030405000001"),"to":ObjectId("5a934e000102030405000002"),"acknowledged":true,date:"2020-04-17T18:26:33.353+00:00"},{"from":ObjectId("5a934e000102030405000002"),"to":ObjectId("5a934e000102030405000001"),"acknowledged":false,date:"2020-04-17T18:26:34.353+00:00"}],}
Query
db.Message.aggregate([{$match:{$or:[{from:{$in:[ObjectId("5a934e000102030405000001")]}},{to:{$in:[ObjectId("5a934e000102030405000001")]}}]}},{$sort:{date:-1}},{$group:{_id:{userConcerned:{$cond:[{$in:["$to",[ObjectId("5a934e000102030405000001")]]},"$to","$from"]},interlocutor:{$cond:[{$in:["$to",[ObjectId("5a934e000102030405000001")]]},"$from","$to"]}},id:{$first:"$_id"},from:{$first:"$from"},acknowledged:{$first:"$acknowledged"},to:{$first:"$to"},date:{$first:"$date"}}},{$lookup:{from:"User",localField:"to",foreignField:"_id",as:"to"}},{$unwind:"$to"},{$lookup:{from:"User",localField:"from",foreignField:"_id",as:"from"}},{$unwind:"$from"},{$project:{_id:0,date:1,acknowledged:1,from:"$from._id",to:"$to._id"}}])