我正在尝试使用以下命令将 json 文件导入数据库:
mongoimport --db db_name --collection collection_name file.json --jsonArray
但它不起作用,我收到此错误:
Tue Oct 21 15:42:20.176 check 0 0
Tue Oct 21 15:42:20.176 imported 0 objects
Tue Oct 21 15:42:20.176 ERROR: encountered 1 error(s)
我正在使用 MongoDB 2.4.9。接下来我可以尝试什么?
编辑
将 -vvvv
添加到命令中会产生以下结果:
Tue Oct 21 16:02:48.582 creating new connection to:127.0.0.1:27017
Tue Oct 21 16:02:48.583 BackgroundJob starting: ConnectBG
Tue Oct 21 16:02:48.584 connected connection!
connected to: 127.0.0.1
Tue Oct 21 16:02:48.584 ns: ip.ip_data
Tue Oct 21 16:02:48.585 filesize: 3526
Tue Oct 21 16:02:48.585 User Assertion: 13293:BSON representation of supplied JSON array is too large: code FailedToParse: FailedToParse: Date expecting integer milliseconds: offset:211
最佳答案
当您使用jsonArray
时数组总大小必须小于 16MiB,否则您将收到该错误。您实际上正在执行批量插入,其中包含数组的单个文档作为插入发送,服务器将此解释为每个数组元素的插入,但总数不能大于 largest permissible BSON document 。
如果你把它分成更小的数组并导入它们,你就可以了,或者你可以使用一些代码来展开数组并直接导入结果。
关于json - Mongoimport JSON文件错误: "BSON representation of supplied JSON array is too large: code FailedToParse: Date expecting integer milliseconds",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26495085/