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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s