MongoDB Import JSON Error – Unmarshalling Bytes

While importing data from a JSON file into MongoDB using following command  –

mongoimport --db my_db --collection my_collection --file json_file.json

if you encounter following error –

Failed: error unmarshaling bytes on document #0: JSON decoder out of sync - data changing underfoot?

Solution:

Mos probable reason is some parts of JSON Objects are not properly formatted. For that you need to use –jsonArray flag with the command.

mongoimport --db my_db --collection my_collection --file json_file.json --jsonArray