3

我正在尝试在执行此命令时通过 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},
4

4 回答 4

4

MongoDB 要求导入的 JSON 格式正确。JSON 相当严格,因此请使用JSONLint来验证您的 JSON 并确定其格式有什么问题。

于 2013-08-27T18:30:00.837 回答
3

mongodbimport 想要传统格式的 json 文件,这意味着除了 [] 之外,只包含 {} 中的键值。

因此,您需要在命令末尾添加一个 --jsonArray,例如:

mongoimport -d test -c user /Users/XXX/json.dat --jsonArray
于 2013-11-27T03:37:53.950 回答
3

我有同样的问题。我使用了错误的工具

我使用mongodump “导出” ,并尝试使用 mongoimport 加载数据。

我不得不使用mongorestore “导入”

请参阅http://docs.mongodb.org/manual/reference/program/mongorestore/

我希望这对某人有用。

于 2014-10-21T09:11:00.443 回答
0

为了避免这个问题,因为它是由于解析了你的 json(1 个文档) 的一部分,所以你需要添加 -jsonArray 这将占用整个 json (所有文档) 并完成。

于 2014-05-15T09:00:07.647 回答