Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed: error processing document in mongoimport

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,

like image 293
Vikash Avatar asked Sep 03 '16 10:09

Vikash


1 Answers

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

like image 176
DAXaholic Avatar answered Nov 14 '22 17:11

DAXaholic