How to replace substring in mongodb document

2019-01-04 02:11发布

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

7条回答
做个烂人
2楼-- · 2019-01-04 02:50

Currently, you can't use the value of a field to update it. So you'll have to iterate through the documents and update each document using a function. There's an example of how you might do that here: MongoDB: Updating documents using data from the same document

查看更多
登录 后发表回答