Mahadevan
Mahadevan

Reputation: 131

Importing JSON or CSV file in MongoDB

I'm new to MongoDB in Windows 7 and I tried to import JSON and CSV file into MongoDB.

1.First i tried importing JSON file using the command

"C:\>mongodb\bin\mongoimport –host localhost:27017 –db mydb –collection docs"

and it showed this error

"exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Expecting '{': offset:0" 

2.When i import CSV file i used the command

"C:\mongodb\bin>mongoimport --db mynewdb --collection message --type csv --fields
form,Iname,fistname,lastname --file d:\new folder\csv1.csv" 

and i get the error message as

"ERROR: multiple occurrences
Import CSV, TSV or JSON data into MongoDB.
When importing JSON documents, each document must be a separate line of the input file"

I downloaded JSON and CSV bulk file randomly by browsing. I want to know whether it will get imported when data's are non-organized or should the data be organized? If so where can get a complete bulk JSON and CSV file which is ready to import.

Upvotes: 0

Views: 1317

Answers (1)

Sam Wolfand
Sam Wolfand

Reputation: 54

Try using the --jsonArray flag at the end of your query so it would look like

C:\>mongodb\bin\mongoimport –host localhost:27017 –db mydb –collection docs --jsonArray

Upvotes: 1

Related Questions