MongoDB

Importing JSON Records into MongoDB with mongoimport

If MongoDB is installed in the C:\MongoDB folder, and the file to be imported is located at C:\Data.json, the format of the mongoimport command is:

 C:\>mongodb\bin\mongoimport –host localhost:27017 –db myblogdb –collection posts > C:\Data.json  

In this example, “myblogdb” is the name of the database and “posts” is the name of the collection into which the data will be inserted.

Note that “localhost:27017” is the default server and port for MongoDB

The database and collection will be created if they do not already exist.

Leave a comment