Search code examples
mongodbcsvmongoimport

Import csv to mongodb database


I am using this code to import my data from csv to mongodb:

./mongoimport -d <db_name> -c <collection_name> --type csv --file <file_location/file.csv> --headerline

But I get the following error:

Failed: line 1, column 2446: extraneous " in field

How to resolve this issue?


Solution

  • Well without showing us your problematic CSV data it is difficult to give you a definitive answer but the error is usually caused when you have a CSV column wrapped in double quotes which contain a double quote within the wrapped text e.g.

    C1,C2  
    57,"This is a double quote:""
    

    To solve the issue you have to escape the double quote with another one like so

    C1,C2  
    57,"This is a double quote:"""