6

I am getting the below error while reading a csv file:

Failed: error processing document #1: invalid character 'a' in literal new or null (expecting 'e' or 'u')

There are some blank fields, which I am suspecting needs to be presented as 'null' to be read properly. Am I correct here?

SAMPLE CSV:

name,year,battle_number,attacker_king,defender_king,attacker_1,attacker_2,attacker_3,attacker_4,defender_1,defender_2,defender_3,defender_4,attacker_outcome,battle_type,major_death,major_capture,attacker_size,defender_size,attacker_commander,defender_commander,summer,location,region,note

Battle of the Golden Tooth,298,1,Joffrey/Tommen Baratheon,Robb Stark,Lannister,,,,Tully,,,,win,pitched battle,1,0,15000,4000,Jaime Lannister,"Clement Piper, Vance",1,Golden Tooth,The Westerlands,

Battle at the Mummer's Ford,298,2,Joffrey/Tommen Baratheon,Robb Stark,Lannister,,,,Baratheon,,,,win,ambush,1,0,,120,Gregor Clegane,Beric Dondarrion,1,Mummer's Ford,The Riverlands,

1
  • I tried adding null in place of empty string, but it still gives the same error Commented Sep 3, 2016 at 11:02

2 Answers 2

11

I guess you didn't specify the file type with --type csv so mongoimportassumes you import a JSON file by default

--> Try to import with --type csv --headerline

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. In AWS documentation, it missing the following 3 lines in CSV file import. --type=csv \ --headerline \ --ignoreBlanks \ After I added the following 3 lines to the code as following, the CSV file was imported successfully to AWS documentdb.
0

In AWS documentation, it missing following 3 lines in CSV file import.

    --type=csv \
--headerline \
--ignoreBlanks \

After I added following 3 lines to the code as following, CSV file imported successfuly to AWS documentdb.

mongoimport --ssl \
--host="sample-cluster.node.us-east-1.docdb.amazonaws.com:27017" \
--collection=sample-collection \
--db=sample-database \
--type=csv \
--headerline \
--ignoreBlanks \
--file=<yourFile> \
--numInsertionWorkers 4 \
--username=sample-user \
--password=abc0123 \
--sslCAFile rds-combined-ca-bundle.pem

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.