Query1
PlayMongo
aggregate(
[{"$set": {"m": "www.google.com", "r": "www.test.com"}},
{"$set":
{"contacts":
{"$map":
{"input": "$contacts",
"in":
{"$mergeObjects":
["$$this",
{"email":
{"$let":
{"vars": {"index": {"$indexOfCP": ["$$this.email", "$m"]}},
"in":
{"$cond":
[{"$eq": ["$$index", -1]}, "$$this.email",
{"$concat":
[{"$substrCP":
["$$this.email", 0, {"$subtract": ["$$index", 0]}]},
"$r",
{"$substrCP":
["$$this.email",
{"$add": ["$$index", {"$strLenCP": "$m"}]},
{"$subtract":
[{"$strLenCP": "$$this.email"},
{"$add":
["$$index", {"$strLenCP": "$m"}]}]}]}]}]}}}}]}}}}},
{"$unset": ["m", "r"]}])
Query2
$replaceAll MongoDB >= 4.4
PlayMongo
aggregate(
[{"$set":
{"contacts":
{"$map":
{"input": "$contacts",
"in":
{"$mergeObjects":
["$$this",
{"email":
{"$replaceAll":
{"input": "$$this.email",
"find": "www.google.com",
"replacement": "www.test.com"}}}]}}}}}])