Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert json file into mongodb

Tags:

mongodb

I am new to MongoDB. After installing MongoDB in Windows I am trying to insert a simple json file using the following command:

C:\>mongodb\bin\mongoimport --db test --collection docs < example2.json 

I am getting the following error:

connected to: 127.0.0.1 Fri Oct 18 09:05:43.749 exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Field name expected: offset:43 Fri Oct 18 09:05:43.750 Fri Oct 18 09:05:43.750 exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Expecting '{': offset:0 Fri Oct 18 09:05:43.751 Fri Oct 18 09:05:43.751 exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Field name expected: offset:42 Fri Oct 18 09:05:43.751 Fri Oct 18 09:05:43.751 exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Expecting '{': offset:0 Fri Oct 18 09:05:43.751 Fri Oct 18 09:05:43.752 exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Field name expected: offset:44 Fri Oct 18 09:05:43.752 Fri Oct 18 09:05:43.752 exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Expecting '{': offset:0 Fri Oct 18 09:05:43.752 Fri Oct 18 09:05:43.752 check 0 0 Fri Oct 18 09:05:43.752 imported 0 objects Fri Oct 18 09:05:43.752 ERROR: encountered 6 error(s)s 

example2.json

{"FirstName": "Bruce", "LastName": "Wayne",  "Email": "[email protected]"} {"FirstName": "Lucius", "LastName": "Fox",  "Email": "[email protected]"} {"FirstName": "Dick", "LastName": "Grayson",  "Email": "[email protected]"} 

What do I need to do to import new json file into mongodb?

like image 626
Jay Avatar asked Oct 18 '13 03:10

Jay


People also ask

Can we import JSON in MongoDB?

The process to import JSON into MongoDB depends on the operating system and the programming language you are using. However, the key to importing is to access the MongoDB database and parsing the file that you want to import. You can then go through each document sequentially and insert into MongoDB.

Can we save JSON in MongoDB?

First, we need to have our JSON file which we will import to the MongoDB database. So we will create a new folder called project . In this folder, create a new file and name it file. json then paste the code in the snippets below into that file.


1 Answers

Use

mongoimport --jsonArray --db test --collection docs --file example2.json 

Its probably messing up because of the newline characters.

like image 158
Leon Avatar answered Sep 19 '22 04:09

Leon