Database

[{"key":1,"codes":["a","b","c","d"]},{"key":2}]

Query

db.collection.aggregate([{"$match":{"codes":{"$in":["a","b","c"]}}},{"$set":{codes:{$setIntersection:["$codes",["a","b","c"]]}}}])

Result