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
{"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?
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.
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.
Use
mongoimport --jsonArray --db test --collection docs --file example2.json
Its probably messing up because of the newline characters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With