Cannot convert data type

“AU”: “[‘SHERMAN T’, ‘MARGALIT I’, ‘COREM S’]”
——I want to convert this data from string to array
db.collection.find({“AU.$”:{$type:2}}).forEach(function(x){x.AU=Array(x.AU);db.collection.save(x)})

[Error] TypeError: db.collection.find(…).forEach(…) is undefined

The function db.collection.find() does not return a container. It returns a cursor. If you want to use forEach() you must call something like toArray().

1 Like