Database
[{message_id:1,participants:["user1","user2"]},{message_id:2,participants:["user2","user1"]},{message_id:3,participants:["user3","user4"]},{message_id:4,participants:["user4","user3"]},]
Query
db.collection.aggregate([{"$addFields":{"participants":{"$cond":[{"$lt":[{"$strcasecmp":[{"$arrayElemAt":["$participants",0]},{"$arrayElemAt":["$participants",1]}]},0]},"$participants",{"$reverseArray":"$participants"}]}}},{"$group":{"_id":"$participants"}},{"$project":{"_id":0,"distinctParticipants":"$_id"}}])