我正在尝试在mongodb集合中导入以下数据
[
{"_id":NumberLong(1), "name": "Afghanistan", "code": "AF"},
{"_id":NumberLong(2), "name": "Aland Islands", "code": "AX"},
{"_id":NumberLong(3), "name": "Albania", "code": "AL"},
{"_id":NumberLong(4), "name": "Algeria", "code": "DZ"},
{"_id":NumberLong(5), "name": "American Samoa", "code": "AS"},
{"_id":NumberLong(6), "name": "AndorrA", "code": "AD"}
]
我收到错误 -
D:\mongodb\bin>mongoimport --db mopi --collection somecountry --type json --file
somecountry.json --jsonArray
connected to: 127.0.0.1
Fri Nov 07 14:20:45.149 exception:BSON representation of supplied JSON array is
too large: code FailedToParse: FailedToParse: Bad characters in value: offset:7
Fri Nov 07 14:20:45.151 [
{"_id":NumberLong(1), "name": "Afghanistan", "code": "AF"},
{"_id":NumberLong(2), "name": "Aland Islands", "code": "AX"},
{"_id":NumberLong(3), "name": "Albania", "code": "AL"},
{"_id":NumberLong(4), "name": "Algeria", "code": "DZ"},
{"_id":NumberLong(5), "name": "American Samoa", "code": "AS"},
{"_id":NumberLong(6), "name": "AndorrA", "code": "AD"}
]
Fri Nov 07 14:20:45.152 check 0 0
Fri Nov 07 14:20:45.153 imported 0 objects
Fri Nov 07 14:20:45.153 ERROR: encountered 1 error(s)
答案 0 :(得分:0)
我假设您向我们展示了数据的缩写。错误表明您的JSON产生的BSON超过了16MB的硬限制。您可以通过重新格式化数据来解决问题。不是将多个文档放在一个数组中并使用--jsonArray导入,这会将总导入大小限制为16MB,而是每行放一个json文档:
{"_id":NumberLong(1), "name": "Afghanistan", "code": "AF"},
{"_id":NumberLong(2), "name": "Aland Islands", "code": "AX"},
{"_id":NumberLong(3), "name": "Albania", "code": "AL"},
{"_id":NumberLong(4), "name": "Algeria", "code": "DZ"},
{"_id":NumberLong(5), "name": "American Samoa", "code": "AS"},
{"_id":NumberLong(6), "name": "AndorrA", "code": "AD"}
...