Mongo Playground

Configuration

db={"users":[{"_id":"0b3bb0bb2d78405fa941dd3e1da9574a","status":true,"fullName":"Irtza","mobileNumber":"+9200000000000","createdAt":{"$date":"2021-05-05T11:39:00.875Z"},"updatedAt":{"$date":"2021-06-04T11:10:53.103Z"},"__v":0,},{"_id":"51701df06d084003853cd0837d76606a","status":true,"fullName":"Shehroz Ali","mobileNumber":"+10000000000","createdAt":{"$date":"2021-05-06T11:28:48.980Z"},"updatedAt":{"$date":"2021-06-04T12:34:03.676Z"},"__v":0,}],"conversations":[{"_id":"9a4d221ebbde4ba68b28783232aed28c","userIds":["0b3bb0bb2d78405fa941dd3e1da9574a","51701df06d084003853cd0837d76606a"],"type":"private","conversationName":"abc","createdAt":{"$date":"2021-06-04T10:46:43.061Z"},"updatedAt":{"$date":"2021-06-04T10:46:43.061Z"},"__v":0}]}

Query

db.conversations.aggregate([{"$match":{"userIds":"0b3bb0bb2d78405fa941dd3e1da9574a"}},{"$unwind":"$userIds"},{"$match":{"userIds":{"$ne":"0b3bb0bb2d78405fa941dd3e1da9574a"}}},{"$lookup":{"from":"users","localField":"userIds","foreignField":"_id","as":"userIds"}}])

Result