I have alot of mongodb documents in a collection ABC of the form:
{
....
"URL":"www.abc.com/helloWorldt/..."
.....
}
I want to replace helloWorldt with helloWorld Final Output:
{
....
"URL":"www.abc.com/helloWorld/..."
.....
}
how do i achieve this for all documents in the collection ABC
Just in case if you are using examples from the answers here and get "Updated 0 existing records" when running your replace script, check whether your client is connected to the primary MongoDB node that allows you to store/write changes.
nodejs. Using mongodb package from npm
To replace ALL occurrences of the substring in your document use:
The formatting of my comment to the selected answer (@Naveed's answer) has got scrambled - so adding this as an answer. All credit goes to Naveed.
----------------------------------------------------------------------
Just awesome. My case was - I have a field which is an array - so I had to add an extra loop.
My query is:
Now you can do it!
We can use Mongo script to manipulate data on the fly. It works for me!
I use this script to correct my address data.
Example of current address: "No.12, FIFTH AVENUE,".
I want to remove the last redundant comma, the expected new address ""No.12, FIFTH AVENUE".
Hope this helps!