how to import json file in mongodb?

If you have a large collection, --jsonArray takes a very long time to import. I was getting about 10 documents/second. If you have a properly formatted .json file you can just use --file instead. I'm getting about 6000 documents/second now.

Good thing I didn't settle for the first option!


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.

Tags:

Json

Mongodb