I have below Mongo Collection
{
"name":"test",
"work":"BA",
"contacts":[
{
"company":"xyz",
"email":"http://www.google.com/check/com/2"
},
{
"company":"xyz1",
"email":"http://www.google.com/verify/com/4"
}
]
}
I want to replace www.google.com from contacts email to www.test.com, Not complete URL only a particular string from email.
Any help appreciated!!
2
Answers
Query1
$indexOfCP
MongoDB >=3.6PlayMongo
Query2
$replaceAll
MongoDB >= 4.4PlayMongo
4.4+ :
Explained:
Update via aggregation pipeline using replaceOne via $map/mergeObjects
playground