Question

How can I import a CSV file that contains some non-UTF8 characters to MongoDB? I tried a recommended importing code.

mongoimport --db dbname --collection colname --type csv --headerline --file D:/fastfood.xls

Error Message

exception: Invalid UTF8  character detected

I would remove those invalid characters manually, but the size of the data is considerably big.

Tried Google with no success.

PS: mongo -v = 2.4.6

Thanks.

Edit: BTW, I'm on Win7

Was it helpful?

Solution

In Linux you could use the iconv command as suggested in: How to remove non UTF-8 characters from text file

iconv -f utf8 -t utf8 -c file.txt

I'm not familiar with MongoDB, so I have no insight on how to preserve the invalid characters during import.

OTHER TIPS

For emacs users: Open CSV file in emacs and change encoding using ‘C-x C-m f’ and choosing utf-8 as the coding system. For more information see ChangingEncodings

You're trying to import an xls file as a csv file. Save the file as csv first, then try again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top