Convert String to Array

I have one scenario to be change existing string variable to List of string.

For example:
“empName” : “Shiva” - This need to change to “empName” : [“Shiva”]

I need to run it in our production database. I would like to know your suggestions any option to run query or any simple steps to do this change directly in database?

Thanks in advance for your answers.

Hello, this is a old question but i will leave the answer here for anyone finding this in the future, you can achieve this easily after mongo 4.2+ by running this on mongodb shell:

db["Collection"].updateMany({}, [{ $set: { fieldToConvert: ["$fieldToConvert"]}}])

Explaining each parameter, the fist ‘{}’ is the where argument, if you want to convert the entire collection just leave empty, and on the $set will change the field that you name there, and you reference the same field using $ so mongo will parse the value inside