Database

[{"_id":1,"locations":[{"code":{"defaultValue":"IL1"},"locationSpecifications":[{"code":{"defaultValue":"LS1"},"minimumCount":{"defaultValue":"0"}},{"code":{"defaultValue":"LS2"},"minimumCount":{"defaultValue":"1"}}]}]}]

Query

db.collection.find({"_id":1,locations:{"$elemMatch":{"code.defaultValue":"IL1",locationSpecifications:{"$elemMatch":{"code.defaultValue":"LS1"}}}}},{_id:1,locations:{$map:{input:{$filter:{input:"$locations",cond:{$and:[{$eq:["$$this.code.defaultValue","IL1"]},{$in:["LS1","$$this.locationSpecifications.code.defaultValue"]}]}}},as:"location",in:{$mergeObjects:["$$location",{locationSpecifications:{$filter:{input:"$$location.locationSpecifications",cond:{$eq:["$$this.code.defaultValue","LS1"]}}}}]}}}})

Result