Im having trouble replacing a substring in some documents. This would be the example of one of the many similar documents:
{
"images" : [
{
"url" : "https://example/1234"
},
{
"url" : "https://example/afaef"
},
{
"url" : "https://example/abcdef"
}
]}
I need to replace all the 'example' substrings for say 'newresult'
This is my approach
db.collection.find({'images.url':/.*example*/} , {'images.url':true, _id:false}).forEach(function(doc) {
doc.images.url = doc.images.url.replace('example', 'newresult');
db.collection.save(doc);});
However im getting many errors trying different forms of this like doc.images.url is undefined. Also tried some different yet still unsuccesful variations of this.
I would really appreciate some insights on what im doing wrong, or if theres a better way to do this. Thanks.