Mongodb Mongoimport too large: Failure parsing err

2019-01-21 22:43发布

I am trying to import into MongoDB 70 mb json file that is valid. But, I am getting this error over and over in a loop:

 01 11:42:20 exception:BSON representation of supplied JSON is too large: Failure parsing JSON string near: "name": "L
 01 11:42:20
 01 11:42:20 Assertion: 10340:Failure parsing JSON string near: "link": "h
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 kernel32.dll       BaseThreadInitThunk+0x12
 01 11:42:20 ntdll.dll          RtlInitializeExceptionChain+0xef
 01 11:42:20 exception:BSON representation of supplied JSON is too large: Failure parsing JSON string near: "link": "h
 01 11:42:20
 01 11:42:20 Assertion: 10340:Failure parsing JSON string near: }
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 kernel32.dll       BaseThreadInitThunk+0x12
 01 11:42:20 ntdll.dll          RtlInitializeExceptionChain+0xef
 01 11:42:20 exception:BSON representation of supplied JSON is too large: Failure parsing JSON string near: }
 01 11:42:20
 01 11:42:20 Assertion: 10340:Failure parsing JSON string near: ],
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 mongoimport.exe    ???
 01 11:42:20 kernel32.dll       BaseThreadInitThunk+0x12
 01 11:42:20 ntdll.dll          RtlInitializeExceptionChain+0xef
 01 11:42:20 exception:BSON representation of supplied JSON is too large: Failure parsing JSON string near: ],

My JSON ( only small example from it ) consist many many structures like this one :

[ 
{
   "data": [
         "id": "xxxxxxxxxxxxxxxxxx",
         "from": {
            "name": "yyyyyyyyyyy",
            "id": "1111111111111"
         },
         "to": {
            "data": [
               {
                  "version": 1,
                  "name": "1111111111111",
                  "id": "1111111111111"
               }
            ]
         },
         "picture": "fffffffffffffffffffffff.jpg",
         "link": "http://www.youtube.com/watch?v=qqqqqqqqqqqqq",
         "source": "http://www.youtube.com/v/qqqqqqqqqqqqq?version=3&autohide=1&autoplay=1",
         "name": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
         "description": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...",
         "icon": "http://static.ak.fbcdn.net/rsrc.php/v2/xxx/r/dddd",
         "actions": [
            {
               "name": "Comment",
               "link": "http://www.example.com/1111111111111/posts/1111111111111"
            },
            {
               "name": "Like",
               "link": "http://www.example.com/1111111111111/posts/1111111111111"
            }
         ],
         "privacy": {
            "value": ""
         },
         "type": "video",
         "created_time": 1356953890,
         "updated_time": 1356953890,
         "likes": {
            "data": [
               {
                  "name": "jjj ",
                  "id": "59xxx67"
               },
               {
                  "name": "xxxxx",
                  "id": "79xxx27"
               }
            ],
            "count": 2
         },
         "comments": {
            "count": 0
         }
      },

....
....
....
}
]

this is the general patern of the json ":

[
{
   "data": [
      {

      }
    ],
    "paging": {
      "previous": "link",
      "next": "link"
   }
},
   "data": [
      {
      }
    ],
    "paging": {
      "previous": "link",
      "next": "link"
   }
},
"data": [
      {
      }
    ],
    "paging": {
      "previous": "link",
      "next": "link"
   }
}
]

5条回答
不美不萌又怎样
2楼-- · 2019-01-21 23:02

Is your json file only contains a list of records in the data field? In that case, you need to re-format your json file as a list of records like the following:

     {
     "id": "xxxxxxxxxxxxxxxxxx",
     "from": {
        "name": "yyyyyyyyyyy",
        "id": "1111111111111"
     },
     "to": {
        "data": [
           {
              "version": 1,
              "name": "1111111111111",
              "id": "1111111111111"
           }
        ]
     },
     ......
     }
     {
     "id": "xxxxxxxxxxxxxxxxxx",
     "from": {
        "name": "yyyyyyyyyyy",
        "id": "1111111111111"
     },
     "to": {
        "data": [
           {
              "version": 1,
              "name": "1111111111111",
              "id": "1111111111111"
           }
        ]
     },
     ......
     }

Just edit the a few leading/ending lines should be enough if your json file is well formatted.

EDIT: You may need the --jsonArray option to import from a valid json file. try

mongoimport --db DATABASE_NAME --collection COLLECTION_NAME --file YOUR_JSON_FILE --jsonArray
查看更多
在下西门庆
3楼-- · 2019-01-21 23:06

In my case, when faced with this error, I found that the problem was from copying and pasting the data from my local machine (in vim) to my remote server (also vim). When I scp'd it across instead it miraculously worked, so no idea what was being changed when copying it across, especially as it was copying from Mac to Centos, so no line ending issues.

In conclusion: use the file that mongoexport creates, not its contents!

查看更多
放我归山
4楼-- · 2019-01-21 23:22

In my case my file was actually not too large, so the error message was misleading. I had to either put each document in a single line or use --jsonArray.

So either change the file like:

{ "_id" : "xxxxxxxx", "foo" : "yyy", "bar" : "zzz" }

or change the import command to

mongoimport -d [db_name] -c [col_name] --file [file_with_multi_lined_docs] --jsonArray

if my file stays in the multiple-lines-per-document format

{
    "_id" : "xxxxxxxx", 
    "foo" : "yyy", 
    "bar" : "zzz" 
}
查看更多
ら.Afraid
5楼-- · 2019-01-21 23:23

Check the version of mongo, I had the problem that I exported json from mongo 2.6.1 and tried to import on a mongo ~2.4, after installing a higher version it worked for me...

查看更多
再贱就再见
6楼-- · 2019-01-21 23:27

Instead of using:

mongoimport -d DATABASE_NAME -c COLLECTION_NAME --file YOUR_JSON_FILE

use the following command:

mongoimport -d DATABASE_NAME -c COLLECTION_NAME --file YOUR_JSON_FILE --jsonArray
查看更多
登录 后发表回答