How to change the data type from string to array

“MC”: “[‘B04-E13’, ‘B04-L05A2’, ‘B04-P01A0E’, ‘D05-H16A’, ‘D05-H19C’, ‘P14-A05’, ‘P14-E02C’]”
This is a field in my collection ,
When I change the data type in the field MC from string to array, the result always appears:
“IP”: [ undefined ],
Here is my code:

How can I fix it? As a rookie in this field, I don’t know why the problem occurs

Hi @M_M-m

I think you must use something like JSON.parse(doc.MC) to parse this.

db.getCollection("test_ge"). updateOne({_id : doc._id},{$set : {IP : JSON.parse(doc.MC)}});

I haven’t tested this code! Its just a pseudo suggestion.

Thanks
Pavel

Thanks, I will try it

[Error] SyntaxError: missing ; before statement
The method does not seem to work very well, maybe there is something wrong with my application?