Database

[{"toystore":22,"toystore_name":"Toystore A","toys":[{"toy":"buzz","code":17001,"price":500},{"toy":"woddy","code":17002,"price":1000},{"toy":"pope","code":17003,"price":300}]},{"toystore":11,"toystore_name":"Toystore B","toys":[{"toy":"jessie","code":17005,"price":500},{"toy":"rex","code":17006,"price":2000}]}]

Query

db.collection.aggregate([{$match:{"toys.code":{$in:[17001,17003,17005,17005]}}},{$project:{_id:"$toystore_name",toy_array:{$reduce:{input:{$map:{input:[17001,17003,17005,17005],as:"qcode",in:{$filter:{input:"$toys",as:"toy",cond:{$eq:["$$toy.code","$$qcode"]}}}}},initialValue:[],in:{$cond:{if:{$eq:["$$this",[]]},then:"$$value",else:{$concatArrays:["$$value","$$this"]}}}}}}},{$project:{"toy_array.code":0}}])

Result