Reputation: 11
I tried to import formatted json file into mongodb. but always it says that can't insert
{
"marks": [
{
"class": {
"className": "A"
},
"subject": "maths",
"score": 43,
"grade": "a"
},
{
"class": {
"className": "B"
},
"subject": "maths",
"score": 34,
"grade": "c"
}
]
}
what is the reason for this. I used command mongoimport --db sss --collection bbv --file a.json
and the error message is
exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Expecting '{': offset:0
Upvotes: 1
Views: 1878
Reputation: 20573
The json file is ok, but the problem is that to import it to MongoDB it should be in only one document by line. This was already commented by @WiredPrairie in this post:
The file a.json:
{"marks": [{"class": {"className": "A"}, "subject": "maths", "score": 43, "grade": "a"}, {"class": {"className": "B"}, "subject": "maths", "score": 34, "grade": "c"} ] }
Command mongoimport:
$ mongoimport --db sss --collection bbv --file a.json
And the result with Robomongo:
Upvotes: 0
Reputation: 91
I had a similar problem e solve this change de locale.
Run this command for change locale dpkg-reconfigure locales
Upvotes: 0
Reputation: 681
try using
mongoimport -d DATABASE_NAME -c COLLECTION_NAME --file YOUR_JSON_FILE --jsonArray
as the import command instead.
@see: Mongodb Mongoimport too large: Failure parsing errors
Upvotes: 2
Reputation: 222581
You problem is that this is not a valid JSON document.
If you have doubts like this, go to JSON editor and paste it. It has an error on the line 9, and this means that you have to put "a"
there. The same thing is with grade c
Upvotes: 0