Arihant Godha
Arihant Godha

Reputation: 2469

Mongoimport using json :supplied json is too large

I am trying to import a json data to mongo via json file while executing this command

mongoimport --db my_db --collection m_data --type json --file /home/uname/email_my.json -v

I have a complete html stored as one of my key values which contains a number of special characters.I am getting the following error

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 />

I have also tried

mongoimport --db my_db --collection m_data --type json --file /home/uname/email_my.json --jsonArray

but it is skipping all my key,values which contains HTML in it.Any suggestions how I can import this type of data. Note- I can't remove anything from the json file as I want to store that as it is.Any suggestions?Thanks in advance.

Update I am trying to insert a following type of json

{"id": 771564,"mailbox_id": 93,"temp": 0,"toaddress": "address <[email protected]>","to_addr": "[email protected]","fromaddress": "name <[email protected]>","from_addr": "[email protected]","ccaddress": "","cc": "","bccaddress": "","bcc": "","reply_toaddress": "[email protected]","reply_to": "[email protected]","senderaddress": "Lisa Taylor <[email protected]>","sender": "[email protected]","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},

Upvotes: 4

Views: 7511

Answers (4)

Lorenzo Eccher
Lorenzo Eccher

Reputation: 301

I had same problem. I was using the wrong tool.

I "exported" with mongodump and I tried to load data using mongoimport.

I had to "import" using mongorestore.

See http://docs.mongodb.org/manual/reference/program/mongorestore/

I hope this could be useful for someone.

Upvotes: 3

Choulli ILyass
Choulli ILyass

Reputation: 13

To avoid that problem, because it's due to parssing a part of your json(1 document), so you need to add -jsonArray That will took the entire json (All documents) and it's done.

Upvotes: 0

Liora
Liora

Reputation: 31

mongodbimport wants a traditional format of the json file which means only contain key-values within {} other than [].

So you need to put an --jsonArray at the end of the command like:

mongoimport -d test -c user /Users/XXX/json.dat --jsonArray

Upvotes: 3

JohnnyHK
JohnnyHK

Reputation: 311865

MongoDB requires that the imported JSON be correctly formatted. JSON is fairly strict, so use JSONLint to validate your JSON and determine what's wrong with its formatting.

Upvotes: 4

Related Questions