Wednesday, June 18, 2014

How to dump data in to MongoDB.

Here I would like share my first MongoDB practise.

In this post I will start with very initial and essential step to install MongoDB and get dump data into that documents.

First install MongoDB from Here. This will install MongoDB in your c: drive.Now open that folder where mongodb get installed.

Now MongoDB look for data directory so open the command prompt from that location and write below command to create data directory.

- md \data\db 

You can also define specific path by mongod command.

C:\mongodb\bin\mongod.exe --dbpath e:\my\mongodb\data

now once that folder is created you can start MongoDB with by running 
the command mongod as below.

C:\Program Files\MongoDB\bin\mongod.exe

This will results you in text as waiting for connection on localhost:27017 port.
Once that that is ready you can now dump the json file in to database to insert 
documents in collections.

 C:\Program Files\MongoDB\bin\mongorestore "<Path of folder where json file resides>"

This will create database in mongoDB to check that is done sucessfully or not 
we can run mongo shell for it.Whenever you open shell it will take your current
session and will use test db.Open mongo shell from below path :

C:\Program Files\MongoDB\bin\mongo.exe from command prompt and type db.
this will show you your current session db, now type use <your db name>.

now you can check whether we are inside our db or not by just select command.

db.<collection>.findone()

This will show single document in json format.
Thats it!! Your MongDB with collection is ready for further operations.


Very MEAN!!


Thanks.