MongoDB Import Error UTF8 Unexpected Error

Was trying to import a CSV file into Mongo but keep getting the error.

exception:Invalid UTF8 character detected

After a heart racing 30 minutes I found the solution.

First run:

iconv -f ISO-8859-1 -t utf-8 a.txt %3E a8.txt

This command simply convert the file to UTF-8. You can then run the normal Mongo Import:

./bin/mongoimport -d {db_name} -c {collection} --type csv --file a8.txt --headerline

Just remember to change the filenames to your own !

Posted on 2013/04/12 by Johann du Toit

comments powered by Disqus