Import CSV file (contains some non-UTF8 characters) in MongoDb

不羁的心 提交于 2019-12-06 07:07:55

问题


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


回答1:


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.




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/19253581/import-csv-file-contains-some-non-utf8-characters-in-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!