Database

[{"_id":1,"points":1,"monthly":[{"year":2021,"month":7,"points":1},{"year":1,"month":1,"points":1}]},{"_id":2,"points":1,"monthly":[{"year":1,"month":1,"points":1}]},{"_id":3,"points":0,"monthly":[]}]

Query

db.collection.update({"_id":4},[{"$addFields":{"isupsert":{"$not":[{"$ne":[{"$type":"$monthly"},"missing"]}]}}},{"$addFields":{"doc":{"$switch":{"branches":[{"case":"$isupsert","then":{"_id":"$_id","points":5,"monthly":[{"year":2021,"month":7,"points":5}]}},{"case":{"$and":[{"$isArray":["$monthly"]},{"$eq":[{"$size":"$monthly"},0]}]},"then":{"_id":"$_id","points":5,"monthly":[{"year":2021,"month":7,"points":5}]}}],"default":{"$let":{"vars":{"found":{"$not":[{"$eq":[{"$size":{"$filter":{"input":"$monthly","as":"m","cond":{"$and":[{"$eq":["$$m.year",2021]},{"$eq":["$$m.month",7]}]}}}},0]}]}},"in":{"$cond":["$$found",{"$mergeObjects":["$ROOT",{"points":{"$add":["$points",5]},"monthly":{"$map":{"input":"$monthly","as":"m","in":{"$cond":[{"$and":[{"$eq":["$$m.year",2021]},{"$eq":["$$m.month",7]}]},{"$mergeObjects":["$$m",{"points":{"$add":["$$m.points",5]}}]},"$$m"]}}}}]},"$$ROOT"]}}}}}}},{"$replaceRoot":{"newRoot":"$doc"}},{"$unset":["isupsert"]}],{"upsert":true})

Result