MongoDB Tutorial - MongoDB Setup








Install MongoDB On Windows

To install the MongoDB on windows, first download the MongoDB windows version from http://www.mongodb.org/downloads

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.

D:\mongodb\bin>mongod.exe

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

D:\mongodb\bin>mongo.exe
connecting to: test
>db.test.save( { a: 1 } )
>db.test.find()
{ "_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
dbpath=D:\mongodb\data
?
##all output go here
logpath=D:\mongodb\log\mongo.log
?
##log read and write operations
diaglog=3

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