MongoDB how to convert string "abc-1" as "abc-0001"

21 Views Asked by At

In MongoDB how to convert the existing string attribute value "abc-1" with "abc-0001".

For example I have a collection as shown below

[ { "id":"abc-1", "name":"Smith" }, { "id":"abc-2", "name":"John" }... ]

the above collection should update as follows

[ { "id":"abc-0001", "name":"Smith" }, { "id":"abc-0002", "name":"John" }... ]

Thanks in Advance

Simply say, needs to split the string and leading with 0's

0

There are 0 best solutions below