MongoDB Tutorial - MongoDB Setup

Install MongoDB On Windows

To install the MongoDB on windows, first download the MongoDB windows version from

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

Extract downloaded file to c:\ drive.

MongoDB need a data folder to store its files. The default location is c:\data\db. Create this folder first.

Run the following command to start the MongoDB server.


The following code shows how to set the dbpath to different location when starting the MongoDB server.

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

To run the mongodb client, open another command prompt and issue the following command

connecting to: test
> { a: 1 } )
{ "_id" : ObjectId(123311235a56a123), "a" : 1 }

MongoDB config file

The following code shows how to use config file with MongoDB.

Create a MongoDB config file, it's just a text file, for example : d:\mongodb\mongo.config

##store data here
##all output go here
##log read and write operations

Use mongod.exe --config d:\mongodb\mongo.config to start MongoDB server.

d:\mongodb\bin>mongod --config D:\mongodb\mongo.config

Windows Service

To add MongoDB as Windows Service, use the following command.

d:\mongodb\bin> mongod --config D:\mongodb\mongo.config --install

To start MongoDB Service

net start MongoDB

To stop MongoDB Service

net stop MongoDB

To remove MongoDB Service

d:\mongodb\bin>mongod --remove