Import CSV data with Compass, including array data

I’m trying to import data through CSV which includes an array.

To test this out I create a document in Compass, including an array field, export it as CSV, then delete it.

I then try to import it, but when Compass requests to associate fields to types, there is no option for array and it gets imported as a string.

I don’t think Compass can handle complex/mixed data type with CSV option.It will import as strings only.You have to modify the data from string to array by some other means
I think you have to use JSON for such cases
Or may be some option exists in command line mongoimport tool

In the end i just imported the data as a string, then used the included mongo shell to run:

db.collection.find().forEach(x=> { x.array = JSON.parse(x.array);; })
1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.