Database

[{"_id":0,"cash_balance":50,"holdings":[{"name":"item1","code":"code1","quantity":300},{"name":"item2","code":"code2","quantity":100}]}]

Query

db.collection.aggregate([{"$match":{"_id":0,"holdings.code":"code1"}},{"$project":{"_id":0,"holdings.quantity":1}},{"$unwind":"$holdings"},{"$project":{"quantity":"$holdings.quantity"}}])

Result