Import CSV file (contains some non-UTF8 charac

2019-04-12 13:07发布

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

3条回答
仙女界的扛把子
2楼-- · 2019-04-12 13:31

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.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-04-12 13:35

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

查看更多
乱世女痞
4楼-- · 2019-04-12 13:38

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

查看更多
登录 后发表回答