user2511142 user2511142 - 1 month ago 19
JSON Question

how to import json file in mongodb?

i am new to mongodb database . i a creating an application in which data store as a json file.
what i want to do is import that data into mongodb and then display it on command prompt.
i already tried following commands but error is displaying

Failure parsing josn near: }

my command is:

mongoimport -d mydb -c mydb --type json --file glossary.json --headerline


i put json file in c:\mongodb\bin\glossary.json
thanx i advace.

{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}

Answer

Your JSON seems to have only a single object. Format like {..},{..} is expected.

So, use --jsonArray option:

 mongoimport -d mydb -c mycollection --jsonArray < glossary.json

The other option is to format the source document as mongodb expects it to be. This will make loading much faster.