MongoDB的Mongoimport太大:故障解析错误(Mongodb Mongoimport t

2019-07-17 18:10发布

我试图导入到MongoDB的70 MB的JSON文件,该文件是有效的。 但是,我在一个循环中一遍又一遍地得到这个错误:

 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: ],

我的JSON(从它只有很小的例子)是由许多许多建筑物像这样的:

[ 
{
   "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
         }
      },

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

这是JSON“的一般百通:

[
{
   "data": [
      {

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

Answer 1:

而不是使用:

mongoimport -d DATABASE_NAME -c COLLECTION_NAME --file YOUR_JSON_FILE

请使用以下命令:

mongoimport -d DATABASE_NAME -c COLLECTION_NAME --file YOUR_JSON_FILE --jsonArray


Answer 2:

在我的情况,我的文件实际上不是太大,所以错误消息是误导。 我不得不要么把每个文档中的单行或使用--jsonArray

因此,要么更改文件,如:

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

或更改导入命令

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

如果我的文件停留在多线每文档格式

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


Answer 3:

是您的JSON文件仅包含在记录列表data字段? 在这种情况下,你需要重新格式化你的JSON文件中像下面记录的列表:

     {
     "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"
           }
        ]
     },
     ......
     }

只需编辑少数领导/结尾的行应该是不够的,如果你的JSON文件格式完全。

编辑 :您可能需要--jsonArray选项从一个有效的JSON文件导入。 尝试

mongoimport --db DATABASE_NAME --collection COLLECTION_NAME --file YOUR_JSON_FILE --jsonArray


Answer 4:

检查蒙戈的版本,我不得不说我从蒙戈2.6.1出口JSON和尝试导入一个蒙戈〜2.4,安装一个更高的版本,它为我工作后,问题...



Answer 5:

就我而言,当面对这个错误,我发现这个问题是从复制,并从我的本地机(VIM)中的数据粘贴到我的远程服务器(也VIM)。 当我scp倒是它跨越,而不是它奇迹般地工作,所以不知道整个复制时,它发生了什么正在改变,特别是因为它是在Mac复制到Centos的,所以没有行结束的问题。

结论: 使用该文件mongoexport造成的,而不是其内容!



文章来源: Mongodb Mongoimport too large: Failure parsing errors