-2

I have my text file with the following JSON and my text file size is around 60 mb.

{
"houseno":"12345678",
"location":"India"
--
--

}
{
"houseno":"1245678",
"location":"UK"
--
--

}

i want to import all json data in same collection.i m not getting any idea how to import my text file json data into mongodb

Any one have any idea or suggestion how do that ..?

sam140
  • 219
  • 1
  • 5
  • 27

1 Answers1

4

As my experience, you should try mongoimport. Then, you can import your JSON like as follows

// --jsonArray  output to a json array rather than one object per line
mongoimport -d dbName -c collectionNameYouLike --file your.json --jsonArray

Besides, mongoimport seems to have some format requirements about JSON.

It should be like (one json object in one line)

{"houseno":"12345678","location":"India"}
{"houseno":"1245678","location":"UK"}

instead of

{
  "houseno":"12345678",
  "location":"India"
}
{
  "houseno":"1245678",
  "location":"UK"
}

If you omit --jsonArray option, the terminal will complain. Sorry, after writing it down, I find another similar post that might help: mongodb json import.

Anyway, hope it helps. My MongoDB version is 2.6.6.

Community
  • 1
  • 1
Allen Chou
  • 1,229
  • 1
  • 9
  • 12