Mar 9, 2015

How to Install MongoDB on Windows


You can download the latest release of MongoDB from http://www.mongodb.org/downloads, Make sure you get correct version of MongoDB depending upon your windows version.
32-bit versions of MongoDB only support databases smaller than 2GB and suitable only for testing and evaluation purposes.
Now extract your downloaded file in any drive suppose we extract it in c:\\ drive, after extract file you will see a folder “mongodb-win32-x86_64-[version]” Here [version] is the version of MongoDb downloaded. You can rename this file name.
Now open the command prompt and run the following command.

[Your mongodb file location]\bin mongod 
 for example  C: \MongoDB\bin mongod

MongoDB require the folder “data\db” inside MongoDb folder location, the default location for the MongoDB data directory is c:\ MongoDB \data\db.
If you have install the MongoDB at different location, then you need to specify any alternate path for \data\db by setting the path dbpath in mongod.exe. For the same issue following commands
In command prompt navigate to the bin directory present into the mongodb installation folder. Suppose my installation folder is D:\set up\mongodb.

C:\Users\XYZ>d:
D:\>cd "set up"
D:\set up>cd mongodb\bin
D:\set up\mongodb\bin>mongod.exe --dbpath "d:\set up\mongodb\data"

If everything going well it will show a message “Waiting for Connection”. Now open a new command prompt and run following command.

D:\set up\mongodb\bin>mongo.exe
MongoDB shell version: 2.4.7
Use test
>db.test.save( { a: 1 } )
>db.test.find()
{ "_id" : ObjectId(5879b0f65a56a454), "a" : 1 }

This will show that mongodb is installed and run successfully. Next time when you run mongodb you need to issue only commands.

D:\set up\mongodb\bin>mongod.exe --dbpath "d:\set up\mongodb\data"
D:\set up\mongodb\bin>mongo.exe

Note: 32-bit versions of MongoDB only support databases smaller than 2GB and suitable only for testing and evaluation purposes.