Puoi provare sotto l'aggregazione usando $replaceRoot
db.collection.aggregate([
{ "$match": { "codeInstances.name": "b", "type": "Package" }},
{ "$unwind": "$codeInstances" },
{ "$match": { "codeInstances.name": "b", "type": "Package" }},
{ "$replaceRoot": { "newRoot": "$codeInstances" }}
])