1

I'm new to mongodb and while trying to import csv file using the syntax below it returns the error below.The first lines of my csv file is as follows:

Source,"ID","Date","Timestamp","Author","Author ID","Longitude","Latitude","Likes","Comments","Retweets","Text"

Can anyone kindly help me.Thank you in advance ! error output image

C:\Program Files\MongoDB\Server\3.2\bin>mongoimport --db mydatabase 
--collection sites --type csv --headerline --file C:\mydata\sample.csv

Output Error

2016-07-06T16:07:51.395+0200 Failed: line 1, column 134: extraneous " in field

2016-07-06T16:07:51.397+0200 imported 0 documents

Sara
  • 19
  • 3
  • Welcome to SO! It looks like the (first lines of) the csv file might be relevant for answering the question, please add them to the question ("edit") – Stefan Hegny Jul 06 '16 at 15:06
  • Thank you Stefan Hegny! I have added my first line of my csv file.Hope anyone can help me. – Sara Jul 07 '16 at 09:01

1 Answers1

0

It is better Convert CSV file into JSON format or import JSON instead of CSV.

To import JSON as collection of objects then

Example:

JSON1 :

[{"project":"project_1","status":"yes","priority":7},{"project":"project_2","status":"yes","priority":7},{"project":"project_3","status":"yes","priority":7}]

mongoimport --db myDB--collection myCollection --file battles.json --jsonArray

Imprort as single object

JSON2 :

[{"mydata":[{"project":"project_1","status":"yes","priority":7},{"project":"project_2","status":"yes","priority":7},{"project":"project_3","status":"yes","priority":7}]}]

mongoimport --db myDB--collection myCollection --file battles.json

Ref:

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

jsonArray import

error invalid character

Community
  • 1
  • 1
Mahesh K
  • 1,689
  • 3
  • 23
  • 36