Database
[{id:1,name:"resturant1",food:"burger"},{id:2,name:"resturant2",food:"sandwich"},{id:3,name:"resturant2",food:"burger"},{id:4,name:"resturant3",food:"burger"}]
Query
db.collection.aggregate([{$match:{name:{$in:["resturant1","resturant2"]}}},{$setWindowFields:{sortBy:{name:1},output:{foodSet:{$addToSet:"$food",window:{documents:["unbounded",-1]}},}}},{$match:{$expr:{$not:{$in:["$food","$foodSet"]}}}},{$unset:"foodSet"}])