mongoimport:csv文件结束时内部引用字段错误 [英] mongoimport: csv file ends while inside quoted field error

查看:301
本文介绍了mongoimport:csv文件结束时内部引用字段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当导入csv文件到mongo数据库时,我得到一个错误:
异常:CSV文件在引号字段内结束,导入操作中止。我检查了异常描述中引用的实际记录。我能够将该记录独立导入mongodb。当我尝试导入整个文件,它不工作。



这个问题的原因是什么?我没有手动检查该记录,也能够将该记录独立导入mongodb。



根据例外情况:错误是第3行
下面是该行前后的一些行。我使用mongoimport参数

  mongoimport -h 127.0.0.1 -d databasename -c collectionname --type csv --file filelocation --headerline --ignoreBlanks 
连接到:127.0.0.1
异常:CSV文件在引号字段内结束
2014-07-17T22:39:29.629-0700 check 9 6307
2014-07-17T22:39:29.631-0700导入6306个对象
遇到1个错误


$ b b

第1行

 1555502,149 -26 17:13:10,iantist,2014-05-02 17:39:48,http://twitter.com/eiantist,, N,< p> Neuroscientist ,, < / p>&#xA;,21,8,0,, N ,, N ,, N,1442157

第2行

 1555662,794,2012-07-26 18:18:37,olivecoder,2014-05-02 16:09:38,http:// www.linkedin.com/in/olivecoder\",\"Brazil\",\"<p>我是一名软件工程师,专注于自1990年以来为电信行业开发解决方案。我在R& amp; D项目中有巨大的背景,开发用于电信设备,CTI应用,软交换,IVR和其他电信解决方案的固件,导致专利注册。我创立了Mares Telecom为运营商提供增值服务,并为电信市场创造新的技术解决方案。< / p>&#xA;&#xA;< p>< a href =,http ://linkedin.com/in/olivecoder,rel =,nofollow,> http://linkedin.com/in/olivecoder< / a>< / p>&#xA;,135 ,75,8,, N ,, N,42,1693823

第3行

 1556310,15,2012-07-27 00:07:09,Volodymyr Zhabiuk,2013-05-14 01:13:28,http://www.linkedin.com/in/volodymyrzhabiuk,, N ,, N,9 ,0,0,, N ,, N ,, N,1694670

第4行:

 1557339,35 09:27,Brice,2014-05-03 06:00:33,http://fr.linkedin.com/in/bleporini,, N ,, N,7,1 ,0,, N ,, N ,, N,1695972



<第5行:

 1558307,253,2012-07-27 17:06:29 ,PurpleDiane,2014-04-03 22:39:43,http://www.linkedin.com/in/dianedemerschen,San Diego ,, CA,< p> 20+多年的编程经验,主要在计算机辅助设计和制造。早期Fortran,迁移到C。当她有阿尔茨海默氏症时,请照顾我的妈妈。现在更新我的技能在C ++ ,, Java ,, Python和Android编程。至少这是我到目前为止所研究的!< / p>&#xA;&#xA;< p>我在使用我的C ++类时收到了StackOverflow的很多信息,更多,甚至可能有一些帮助。< / p>&#xA;,25,6,1,, N ,, N ,, N,1697171


解决方案

感谢您的帮助!!字段在整个文件的各行有空值!类似的问题解释这里



我实际上从Mysql数据创建了CSV文件,所以我使用这个命令export into csv(but without any escape / enclose conditions)

 选择'column1','column2'
UNION ALL
SELECT *
从Mysqltable
into outfile'Filename.csv';

这导出为csv文件(从Mysql数据库),但在列条目之间没有逗号或包含双引号。



导入到mongo:using same命令,但导入为TSV(制表符分隔值)。

  mongoimport -h 127.0.0.1 -d databasename -c collectionname  - -type tsv --file filelocation --headerline --ignoreBlanks 


While importing a csv file into mongo database, I get an error : exception : CSV file ends while inside quoted field and the import operation aborts. I checked the actual records it was referring to in the exception description. I was able to import that record independently into the mongodb. When I try to import the whole file, it does not work.

What could be the reason for this issue ? I did check that record manually and was also able to import that record independently into the mongodb. Could it still be an issue with quotes/commas orother special characters that might cause a problem ?

According to the exception : error is with Row 3 Here are some more rows before and after that row. I am using mongoimport with parameters

mongoimport -h 127.0.0.1 -d databasename -c collectionname --type csv --file filelocation --headerline --ignoreBlanks
connected to: 127.0.0.1
exception:CSV file ends while inside quoted field
2014-07-17T22:39:29.629-0700 check 9 6307
2014-07-17T22:39:29.631-0700 imported 6306 objects
encountered 1 error(s)

Row 1:

"1555502","149","2012-07-26 17:13:10","iantist","2014-05-02 17:39:48","http://twitter.com/@iantist",,N,"<p>Neuroscientist,, rabid R user at work and home. </p>&#xA;","21","8","0",,N,,N,,N,"1442157"

Row 2:

"1555662","794","2012-07-26 18:18:37","olivecoder","2014-05-02 16:09:38","http://www.linkedin.com/in/olivecoder","Brazil","<p>I am a software engineer focused on developing solutions for the telecommunications industry since 1990. I have a huge background in R&amp;D projects,, developing firmware for telecom equipment,, CTI applications,, softswitches,, IVR and others telecom solutions that resulted in patent registration. I founded Mares Telecom to provide value-added services to carriers and to create new technologic solutions for the telecom market.</p>&#xA;&#xA;<p><a href=,"http://linkedin.com/in/olivecoder," rel=,"nofollow,">http://linkedin.com/in/olivecoder</a></p>&#xA;","135","75","8",,N,,N,"42","1693823"

Row 3:

"1556310","15","2012-07-27 00:07:09","Volodymyr Zhabiuk","2013-05-14 01:13:28","http://www.linkedin.com/in/volodymyrzhabiuk",,N,,N,"9","0","0",,N,,N,,N,"1694670"

Row 4:

"1557339","35","2012-07-27 10:09:27","Brice","2014-05-03 06:00:33","http://fr.linkedin.com/in/bleporini",,N,,N,"7","1","0",,N,,N,,N,"1695972"

Row 5:

"1558307","253","2012-07-27 17:06:29","PurpleDiane","2014-04-03 22:39:43","http://www.linkedin.com/in/dianedemerschen","San Diego,, CA","<p>20+ years programming experience,, primarily in Computer-Aided Design and Manufacturing. Early Fortran,, migrated to C. Took time off to care for my mom when she had Alzheimer's. Now updating my skills in C++,, Java,, Python and Android programming. At least that's what I've studied so far!</p>&#xA;&#xA;<p>I got a lot of information from StackOverflow while I was taking my C++ classes,, now I hope to learn more and perhaps even be of some help.</p>&#xA;","25","6","1",,N,,N,,N,"1697171"

解决方案

Thanks for the help!! Turns out that the issue was with the fields which have null values in various lines throughout the file! A similar issue is explained here.

I actually created the CSV files from Mysql data. So I used this command to export into csv(but without any escape/enclose conditions)

select 'column1','column2'
UNION ALL
SELECT *
    FROM Mysqltable
    into outfile 'Filename.csv';

This got exported as a csv file ( from the Mysql db ) but has no commas between column entries or enclosing double quotes.

For importing into mongo: used same command as above but imported as TSV(tab separated values).

mongoimport -h 127.0.0.1 -d databasename -c collectionname --type tsv --file filelocation --headerline --ignoreBlanks 

Works perfectly now!

这篇关于mongoimport:csv文件结束时内部引用字段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆