【问题标题】:Mongodb Mongoimport too large: Failure parsing errorsMongodb Mongoimport too large: 失败解析错误
【发布时间】:2013-01-01 09:58:09
【问题描述】:

我正在尝试导入有效的 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"
   }
}
]

【问题讨论】:

    标签: json mongodb import


    【解决方案1】:

    而不是使用:

    mongoimport -d DATABASE_NAME -c COLLECTION_NAME --file YOUR_JSON_FILE
    

    使用以下命令:

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

    【讨论】:

    • 我也是! --jsonArray 参数使一切变得不同。可惜它不能只检测到一个 json 数组。
    • 这么简单的烦人问题。我正要编写一个脚本来一次插入一个文档。你救了我。感谢您的快速修复。
    【解决方案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" 
    }
    

    【讨论】:

      【解决方案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
      

      【讨论】:

      • 在这种情况下,您可以使用--jsonArray 选项。试试mongoimport --db DATABASE_NAME --collection COLLECTION_NAME --file YOUR_JSON_FILE --jsonArray
      • 嗨,我得到了一些东西,但仍然错误:mongoimport --collection ping_collaction --file group_result31.12.2012.json --jsonArray Tue Jan 01 16:04:53 exception:JSONArray file too large Tue Jan 01 16 :04:53 警告:日志行尝试 (16384k) 超过最大大小 (10k),打印开始和结束 ... ...一些 json ... 1 月 1 日星期二 16:04:53 导入 0 个对象 1 月 1 日 16 日星期二: 04:53 错误:遇到 1 个错误
      • 警告没有问题,只是告诉你它缩短了行以保持日志文件更小。对于第一个错误,正如@WPCoder 在另一个答案中所建议的那样,是否有任何大于 16MB 的记录?
      • 好吧对不起初学者的问题,但是 mongoDB 看到了什么记录?总文件为 80 兆
      • 是的,它比 16 大,有什么可做的吗? mybe 其他工具?或其他支持 json 的数据库
      【解决方案4】:

      检查 mongo 的版本,我遇到了我从 mongo 2.6.1 导出 json 并尝试在 mongo ~2.4 上导入的问题,安装更高版本后它对我有用...

      【讨论】:

        【解决方案5】:

        就我而言,当遇到此错误时,我发现问题在于将数据从我的本地计算机(在 vim 中)复制并粘贴到我的远程服务器(也是 vim)。当我scp'd 时,它却奇迹般地工作了,所以不知道在复制它时发生了什么变化,特别是当它从 Mac 复制到 Centos 时,所以没有行尾问题。

        结论:使用mongoexport 创建的文件,而不是其内容!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-10-25
          • 1970-01-01
          • 2021-12-25
          • 2017-04-17
          • 1970-01-01
          • 2017-11-20
          • 2013-08-09
          相关资源
          最近更新 更多