Níže můžete vyzkoušet agregaci pomocí $replaceRoot
db.collection.aggregate([
{ "$match": { "codeInstances.name": "b", "type": "Package" }},
{ "$unwind": "$codeInstances" },
{ "$match": { "codeInstances.name": "b", "type": "Package" }},
{ "$replaceRoot": { "newRoot": "$codeInstances" }}
])