I need to replace a portion of string in a collection. I found this answer https://stackoverflow.com/a/60353546/11904736 but I got this error when I try it :
Error: the update operation document must contain atomic operators
So I believe I'm pretty close with the ReplaceOne operator, got no error, but the string I'm searching does not change. I must find every /mordu/episodes/ and replace with /mordu/webseries/ in all the collection for CanonicalWebLink property :
db.mycollections.replaceOne(
{ "CanonicalWebLink": { $regex: "/mordu/\//episodes/" } },
{ "CanonicalWebLink": "/mordu/webseries/"})
Does anyone can explain why this code does not work as I would expect ? CanonicalWebLink is a URL like that : "http://mywebsite/mordu/episodes/2/some-page-slug"