将.csv文件导入mongodb时出现了一个奇怪的错误。这是我一步一步做的:
第1步:我有一个.xlsx并使用UTF-8编码转换为.csv
我的test.xlsx:
index count
1 12
2 14
3 12
4 43
Step 1.1: save as .xlsx file with "Unicode Text (*.txt)"
Step 1.2: open .txt with nodepad and replace tab with ","
Step 1.3: save as .txt and change the file extension from "*.txt" to "*.csv", and choose encoding: to UTF-8
第2步:我在linux shell中使用mongoimport导入到mongodb。这是输出:
mongoimport -d mydb -c test --type csv --file test.csv --headerline
mongoimport: /usr/lib64/libcrypto.so.10: no version information available (required by mongoimport)
mongoimport: /usr/lib64/libssl.so.10: no version information available (required by mongoimport)
2015-12-24T10:21:22.909+0700 connected to: localhost
2015-12-24T10:21:22.910+0700 imported 4 documents
第3步:当我尝试使用索引查找时,我什么也没得到。
db.test.find({"index":"1"})
然后我使用Robomongo来展示我的测试集,在这里我得到了:
你可以在索引字段中看到一个奇怪的字符吗?
答案 0 :(得分:0)
我会说它的BOM(https://en.wikipedia.org/wiki/Byte_order_mark)。
您是否可以选择另存为“没有BOM的Unicode”?
或者,您可以在阅读输入时清除字符。