如何导入CSV文件MongoDB中
问题描述:
我有一个包含以下数据的csv文件,并希望将其导入MongoDB中如何导入CSV文件MongoDB中
ID;"AdmissionID";"SeatNo";"RegistrationNo";"ResultDate";"ResultStatusId"
1;12;"2323";"23";07-05-2013;1
2;23;"35";"32";10-05-2013;5
这个数据将被导入到MongoDB的2.2。我使用下面的命令:
mongoimport -d test -c exam --type csv --headerline <f:\exam.csv
使用我获得以下错误
SyntaxError: missing ; before statement (shell):1
时请帮我找出错误
答
这应该很容易做的伎俩。更多HERE。
mongoimport -d mydb -c collectionName --type csv --file myfile.csv --headerline
你的问题是<f:\exam.csv
位,这是不正确的方式逃脱它看起来
> --headerline
> If using “--type csv” or “--type tsv,” use the first line as field names. Otherwise, mongoimport will import the first line as a distinct
> document.
+0
如何将文件作为参数传递而不是从标准输入中读取帮帮我? – toro2k 2013-05-07 11:44:29
答
请试试这行代码
C:\Program Files\MongoDB\Server\3.2\bin>mongoimport -d pravin -c FOC --type csv
--file D:\Script\ImportData\FOC.csv --headerline
2016-08-10T15:42:38.685+0530 connected to: localhost`enter code here`
2016-08-10T15:42:38.758+0530 imported 13 documents
http://stackoverflow.com/questions/4686500/how-to-use-mongoimport-to-import-csv – ymn 2013-05-07 10:45:02
另外,如参数所示,它应该是逗号分隔值文件,而不是分号。 – WiredPrairie 2013-05-07 11:12:19
您的文件不是“逗号分隔”,而是半逗号(;)。 将其更改为逗号如果使用Windows,或者在UNIX中使用sed命令,然后导入它,请使用excel分隔。 – Sushil 2013-05-07 12:00:05