MongoDB Setup – Installation, Configure and Set up Windows Service
MongoDB Setup – Installation, Configure and Set up Windows Service
Installation on Windows
1. Downloading MongoDB
MongoDB offers several binary distributions, both in 32 & 64-bit flavors for various operating systems. They may be found at the following URL: http://www.mongodb.org/downloads or from their main website click the on downloads link.
2. Creating the Data Directory
By default MongoDB stores its data in C:\data\db directory, however, since mongo does not automatically create it for you it may be necessary to manually create this data directory.
Using a DOS command prompt, we can issue the make directory (mkdir) command to create the necessary directory structure. To ensure that the directory was created correctly, I simply change directory (cd) to the newly created directory structure.
3. Running MongoDB on Windows
On my system, mongoDB was installed in C:\Program Files\MongoDB\2.6.11. You will need to ensure you are in the bin folder. Start the MongoDB daemon process for the system by executing the file mongod.exe. This will handle all data requests, manage the format of the data, and perform the necessary background data management.
Starting the MongoDB in Windows as a Service
1. Create Configuration File
Create a configuration file in
2. Sample Configuration file (mongod.cfg)
dbpath=C:\data\db logpath=C:\data\logs\mongo.log
3. Starting the MongoDB Server
To start the MongoDB database server with default settings (ie: default dbpath C:\data\db) or logging to stdout.
C:\Program Files\MongoDB\2.6.11\bin>mongod.exe
You can choose to set the database path to a directory other the default path of C:\data\db by using the –dbpath argument and instead of using stdout for the logging you can choose to create log files in log_directory by using the –logpath argument.
C:\Program Files\MongoDB\2.6.11\bin>mongod.exe --dbpath <db_directory> --logpath <log_file>
Showing help available for mongod.exe
To show a list of all of the arguments available for mongod.exe process,use the command mongod.exe –help Note: Shown below is just a partial list of all of the help options available.
C:\Program Files\MongoDB\2.6.11\bin>mongod.exe --help Options: General options: -h [ --help ] show this usage information --version show version information -f [ --config ] arg configuration file specifying additional options -v [ --verbose ] be more verbose (include multiple times for more verbosity e.g. -vvvvv) --quiet quieter output --port arg specify port number - 27017 by default --bind_ip arg comma separated list of ip addresses to listen on - all local ips by default --maxConns arg max number of simultaneous connections - 1000000 by default --logpath arg log file to send write to instead of stdout - has to be a file, not directory --logappend append to logpath instead of over-writing --timeStampFormat arg Desired format for timestamps in log messages. One of ctime, iso8601-utc or iso8601-local --pidfilepath arg full path to pidfile (if not set, no pidfile is created) --keyFile arg private key for cluster authentication --setParameter arg Set a configurable parameter --httpinterface enable http interface --clusterAuthMode arg Authentication mode used for cluster authentication. Alternatives are (keyFile|sendKeyFile|sendX509|x509) --auth run with security --noauth run without security ...
3. Installing MongoDB as a Service
Install the MongoDB service by starting mongod with the –install option and the –config option to specify the configuration file, in our example mongod.cfg. Please Note: You may need to use double quotes “” around the entire directory/logfile as it may contain blanks.
cd <MONGODB_INSTALLATION_DIRECTORY> mongod.exe --config "C:\Program Files\MongoDB\2.6.11\bin\mongod.cfg" --install
Component Service

4. Starting MongoDB Service
To start the MongoDB service use the following command:
net start MongoDB
5. Stopping MongoDB Service
To stop the MongoDB service use the following command:
net stop MongoDB
6. Removing the MongoDB Service
To Remove the MongoDB service from Windows use the following command:
mongod.exe --remove
That’s It!
I hope you enjoyed this tutorial. It was certainly a lot of fun putting it together and testing it out. Please continue to share the love and like us so that we can continue bringing you quality tutorials. Happy Coding!!!

Related Posts
- MongoDB Tutorials – Installation, Basics, Core, JAX-RS and Spring Data Examples
This is an index post containing a consolidated list of all of the Mongo related tutorials as well as those using other Frameworks like Spring MVC/Spring Data, and JAX-RS. - MongoDB Setup – Installation, Configure and Set up Windows Service
This MongoDB Setup -tutorial will guide you through installation, configuration setup and show you how to configure MongoDB as a Windows Service. - MongoDB Shell Basics – Insert, Update, Find, Delete and Indexing
In this, MongoDB Shell Basics tutorial we will take you through the basics of using the mongo shell to create, update, delete and find documents in collections. In addition we will show you howto create indexes in collections. - MongoDB Basics – Finding Distinct Values, Using Sort and Finding the Number of Documents in a Collection
In this tutorial we learn about how to use Distinct to find unique fields within a document. In addition, we learn about using Sort and Count methods in MongoDB. - MongoDB Basics – Aggregation and Group Examples Tutorial
In this tutorial we learn about how to use aggregation operations to process data matching a certain criteria and perform some operation to return computed results. - Connecting to MongoDB using JDBC
The JDBC API defines a set of interfaces and classes that all major database providers adhere to in order allow Java developers to seamlessly connect to many Relational Database Management Systems (RDBMS). All major vendors provide their own JDBC drivers which contain a set of java classes that enables you to connect to that particular database. - Java Connecting to MongoDB 3.2 Examples
In this tutorial, Java Connecting to MongoDB 3.2 Examples we will show you different ways to connect to the latest version of MongoDB using Java and their mongo java driver (mongo-java-driver-3.2.0.jar). - MongoDB Java CRUD Operations Example Tutorial
In this tutorial we will focus on using CRUD Operations (Create, Read, Update and Delete) with the latest version of MongoDB using Java and MongoDB Java Driver (mongo-java-driver-3.2.0.jar). We will focus our efforts on insertOne, updateOne, replaceOne, findOneAndUpdate and findOneAndDelete. - MongoDB Java using Find and Query Operations Example Tutorial
In this tutorial we will focus on using Find and Query Operations to retrieve data from a MongoDB collection. We will concentrate on using the following MongoDB operators: ($gt, $lt, $gte, $lte, $in, $nin, $and and $or) with the latest version of MongoDB using Java and MongoDB Java Driver (mongo-java-driver-3.2.0.jar).
Please Share Us on Social Media






Leave a Reply