Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 681
Krisalay Avatar asked Jun 17 '26 05:06

Krisalay


1 Answers

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:"""
like image 148
DAXaholic Avatar answered Jun 20 '26 15:06

DAXaholic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!