Database
[{"_id":"xxx","time":"1643649900000","scores":[{"name":"APPL","price":80},{"name":"GOOGL","price":83,},{"name":"COMPI","price":76,},{"name":"and more names which also can change in the following documents","price":76,}]},{"_id":"yyy","time":"1644350400000","scores":[{"name":"STCMP","price":33},{"name":"APPL","price":95,},{"name":"GOOGL","price":83,},{"name":"MINN","price":76,}]},]
Query
db.collection.aggregate([{"$unwind":"$scores"},{"$group":{"_id":"$time","total":{"$sum":{"$cond":[{"$in":["$scores.name",["APPL","GOOGL"]]},0,"$scores.price"],}}}},])