2
votes

I'm trying to import my json file to a db using the following command:

mongoimport --db db_name --collection collection_name file.json --jsonArray

But it's not working, and I'm getting this error:

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)

I'm using MongoDB 2.4.9. Any help? Thanks.

EDIT: adding -vvvv to the command results in the following:

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
1
mongoimport isn't very informative. Try adding -vvvvv to the commandline to see if gives some more information. - Martin
I've never tried this command before but I did now and added the result as an Edit to the original question. - hello_its_me
The BSON produced from the JSON can't be larger than 16MB. What does the JSON look like? Are you sure you want to use --jsonArray? - wdberkeley

1 Answers

3
votes

When you are using jsonArray the total array size must be less than 16MiB, or you will get that error. You are effectively doing a bulk insert where a single document containing an array is sent as an insert, the server interprets this as an insert per array element, but the total can't be larger than the largest permissible BSON document.

If you break it up into smaller arrays and import those you will be OK, or you could use a bit of code to unwind the array and just do a straight import with the result.