我正在尝试在执行此命令时通过json文件将json数据导入mongo
mongoimport --db my_db --collection m_data --type json --file /home/uname/email_my.json -v
我有一个完整的html存储为我的一个键值,其中包含许多特殊字符。我收到以下错误
Tue Aug 27 00:04:48 exception:BSON representation of supplied JSON is too large: Failure parsing JSON string near: </td>
Tue Aug 27 00:04:48 Assertion: 10340:Failure parsing JSON string near: <td>
0x85a4462 0x8584704 0x8571e83 0x8571f35 0x8385c96 0x81f5cf2 0x81f73cc 0x81e89a1 0x81de4ec 0xb70dc935 0x81ea5cd
Tue Aug 27 00:04:48 Assertion: 10340:Failure parsing JSON string near: <br />
0x85a4462 0x8584704 0x8571e83 0x8571f35 0x8385c96 0x81f5cf2 0x81f73cc 0x81e89a1 0x81de4ec 0xb70dc935 0x81ea5cd
mongoimport(_ZN5mongo15printStackTraceERSo+0x32) [0x85a4462]
mongoimport(_ZN5mongo10logContextEPKc+0x64) [0x8584704]
mongoimport(_ZN5mongo11msgassertedEiPKc+0xb3) [0x8571e83]
mongoimport() [0x8571f35]
mongoimport(_ZN5mongo8fromjsonEPKcPi+0x256) [0x8385c96]
mongoimport(_ZN6Import8parseRowEPSiRN5mongo7BSONObjERi+0x102) [0x81f5cf2]
mongoimport(_ZN6Import3runEv+0xebc) [0x81f73cc]
mongoimport(_ZN5mongo4Tool4mainEiPPc+0x7c1) [0x81e89a1]
mongoimport(main+0x3c) [0x81de4ec]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0xb70dc935]
mongoimport() [0x81ea5cd]
Tue Aug 27 00:04:48 exception:BSON representation of supplied JSON is too large: Failure parsing JSON string near: <br />
我也试过
mongoimport --db my_db --collection m_data --type json --file /home/uname/email_my.json --jsonArray
但它正在跳过我的所有键,其中包含HTML的值。任何建议如何导入此类数据。 注意 - 我无法从json文件中删除任何内容,因为我想存储它。任何建议?提前感谢。
更新 我试图插入以下类型的json
{"id": 771564,"mailbox_id": 93,"temp": 0,"toaddress": "address <abc@xyz.com>","to_addr": "abc@xyz.com","fromaddress": "name <noreply@somesmtp.com>","from_addr": "noreply@somesmtp.com","ccaddress": "","cc": "","bccaddress": "","bcc": "","reply_toaddress": "xyz@yahoo.com","reply_to": "xyz@yahoo.com.au","senderaddress": "Lisa Taylor <noreply@somesmtp.com>","sender": "noreply@somesmtp.com","return_pathaddress": "","return_path": "","email_date": "2013-08-26 14:01:02","subject": "E_form:- some date, 186","flagged": " ","draft": " ","msgno": 18,"MailDate": "0000-00-00 00:00:00","email_size": 13940,"udate": 1377525675,"email_body_txt": "
","email_body_html": "<table width=\"800\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">
<tr>
<td>
<a href=\"http://www.google.com/\" title=\"\"><img src=\"http://www.example.com/images/frontend/logo.png\" width=\"163\" height=\"116\" alt=\"a\" title=\"a\" border=\"0\" /></a>
</td>
</tr>
<tr>
<td>
<table width=\"800px\" border=\"0\">
<tr>
<td>
<a href=\"http://www.example.com/\" title=\"\">Home</a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"3\">
<tr>
<td height=\"39\" colspan=\"3\"><b>Dear Admin,<br />
</b><br />
<b>addf.<br />
</b></td>
</tr>
</table>","unique_msg_no": 246485,"attach_fname": "","domain_id": 0,"myob": 0,"tags": "","form_id": 0,"hashid": "0000-00-00 00:00:00","flag": 1,"domain_name": "","myob_name": "","server_id": 0,"server_name": "","status": 1,"ft_js_id": 0,"response_type": 0},
答案 0 :(得分:4)
MongoDB要求导入的JSON格式正确。 JSON相当严格,因此使用JSONLint验证您的JSON并确定其格式错误。
答案 1 :(得分:3)
mongodbimport需要传统格式的json文件,这意味着只包含除{]之外的{}内的键值。
所以你需要在命令的末尾添加一个--jsonArray,如:
mongoimport -d test -c user /Users/XXX/json.dat --jsonArray
答案 2 :(得分:3)
我有同样的问题。我使用的是错误的工具。
我使用 mongodump “导出”,我尝试使用mongoimport加载数据。
我必须使用 mongorestore “导入”。
请参阅http://docs.mongodb.org/manual/reference/program/mongorestore/
我希望这对某人有用。
答案 3 :(得分:0)
要避免这个问题,因为它是由于解析了json(1个文档)的一部分,所以你需要添加-jsonArray 这将花费整个json(所有文档)并完成。