[mongoimport] Failed: cannot decode 32-bit integer into a slice while importing from json file

Hey, I am trying to import documents from a json-file. I am using the following command:
mongoimport --db test --collection data--file ~/py/data.json --jsonArray
and upon running this I am receiving this message

2020-12-06T08:57:22.763+0000    connected to: mongodb://localhost/
2020-12-06T08:57:23.515+0000    Failed: cannot decode 32-bit integer into a slice
2020-12-06T08:57:23.517+0000    23000 document(s) imported successfully. 0 document(s) failed to import.

It only imports 23000 documents and there are 33300+ documents in that file. The file is 170MB in size. I am using version 4.4.2 if it maters. Any help will be appreciated.

Hi @Abhishek_Singh! This kind of error can occur if the array in your file contains more than just documents. For example, if your file is:

  {"a": 1, "b": 1},
  {"a": 2, "b": 2},
  {"a": 4, "b": 4},

mongoimport will fail because of the value 3. Your file must be an array of documents, and nothing else.

You can check to see if your array contains any values which aren’t documents by using the jq tool:

cat ~/py/data.json | jq '.[] | select(type=="object" | not)'

I hope this helps!

1 Like