How to install MongoDB on Windows

In this tutorial, we will show you how to install MongoDB on Windows.

  1. MongoDB 2.2.3
  2. Windows 7
Note
The MongoDB does not require installation, just download and extracts the zip file, configure the data directory and start it with command “mongod“.

1. Download MongoDB

Download MongoDB from official MongoDB website. Choose Windows 32 bits or 64 bits. Unzip, extracts to your prefer location, for example : d:\mongodb\.

2. Review MongoDB folder

In MongoDB, it contains only 10+ executable files (exe) in the bin folder. This is true, and that are the required files to MongoDB, it’s really hard to believe for a developer like me who come from a relation database background.

Figure : Files under $MongoDB/bin folder

mongodb-windows
Note
It’s recommended to add $MongoDB/bin to Windows environment variable, so that you can access the MongoDB’s commands in command prompt easily.

3. Configuration File

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

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
Note
MongoDB need a folder (data directory) to store its data. By default, it will store in “C:\data\db“, create this folder manually. MongoDB won’t create it for you. You can also specify an alternate data directory with --dbpath option.

4. Run MongoDB server

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


d:\mongodb\bin>mongod --config D:\mongodb\mongo.config
all output going to: D:\mongodb\log\mongo.log

5. Connect to MongoDB

Uses mongo.exe to connect to the started MongoDB server.


d:\mongodb\bin>mongo
MongoDB shell version: 2.2.3
connecting to: test
> //mongodb shell

6. MongoDB as Windows Service

Add MongoDB as Windows Service, so that MongoDB will start automatically following each system restart.

Install as Windows Service with --install.


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

A Windows service named “MongoDB” is created.

mongodb-windows-service

To start MongoDB Service


net start MongoDB

To stop MongoDB Service


net stop MongoDB

To remove MongoDB Service


d:\mongodb\bin>mongod --remove

7. FAQs

1. Install MongoDB as Windows service on Windows 8, but hit “Access is denied.” error message :


C:\Users\mkyong2002>mongod --config D:\mongodb\mongo.config --install
Tue Jul 16 21:05:55.154 diagLogging level=3
Tue Jul 16 21:05:55.155 diagLogging using file D:\mongodb\data/diaglog.51e54533
Tue Jul 16 21:05:55.155 Trying to install Windows service 'MongoDB'
Tue Jul 16 21:05:55.155 Error connecting to the Service Control Manager: Access
is denied. (5)

To fix it, run the Command Prompt with Administrative Privileges – right click on the command prompt icon, select run as administrator.

References

  1. Install MongoDB on Windows
  2. MongoDB configuration options

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
btn
Guest
btn

nice one it saved my lot of time

siva
Guest
siva

HI Mkyong,

This is really very interesting site and useful for all. The way of explaining all the concepts is fabulous. Keep the service !!!

Umesh Pratap Singh
Guest
Umesh Pratap Singh

I followed all the steps for installing which you mentioned. But when I tried to start the server by clicking on mongo.exe or mongod.exe. It gave me an error

“The program cant start because api-ms-win-crt-runtime-|1-1-0.dll is missing from your computer. Try reinstalling the program to fix this problem. ”

MSI file name :- mongodb-win32-x86_64-2008plus-ssl-3.4.1-signed.msi

Oliver Shortnacy
Guest
Oliver Shortnacy

There are two similar ways to solve this problem. This missing file is a part of Microsoft .NET Framework, so the first way to fix it is reinstalling this component. You can easily find it on official Microsoft website https://www.microsoft.com/en-us/download/details.aspx?id=55170, it’s free. You can also download api-ms-win-crt-runtime-|1-1-0.dll from extraneous website, for example https://fix4dll.com/apimswincrtruntimel110_dll. If you decide to download it without NET Framework, don’t forget to add to to registry

Subhobroto Roy
Guest
Subhobroto Roy

Hi Mkyong,

As you have mentioned to go to bin folder in your post for installation mongoDB, but I am not able to find out zip installation file of MongoDb, in the community the download file is in .msi extension available…could you please tell me how can I get the zip file of MongoDB installation so that I follow your above mentioned steps to install MongoDB.

Gena Turkot
Guest
Gena Turkot

Thank you!!!

John Peter
Guest
John Peter

Great article. Do you have any article on MongoDB with Map Reduce

Veeramani Bagavathi
Guest
Veeramani Bagavathi

Steps are very clear.. Finally it started..!!! likes…

Apoorv
Guest
Apoorv
Hooman
Guest
Hooman

method explained in this tutorial is deprecated. Please read the official documentation instead:
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/

Abhilash Patil
Guest
Abhilash Patil

i am getting an exception ,while installing the mongodb

H:mongodbbin>H:mongodbbinmongod.exe –config H:mongodbmongo.config –ins

tall

2015-05-18T22:21:56.445+0530 warning: –diaglog is deprecated and will be remove

d in a future release

2015-05-18T22:21:56.447+0530 diagLogging level=3

2015-05-18T22:21:56.449+0530 diagLogging using file c:mongodbdatadb/diaglog.5

55a18ac

2015-05-18T22:21:56.453+0530 log file “H:mongodblogmongo.log” exists; moved t

o “H:mongodblogmongo.log.2015-05-18T16-51-56”.

RaniD
Guest
RaniD

I am getting this one too. were you able to resolve this? my service is not created.

Sateesh Smart
Guest
Sateesh Smart

Create data and log folder in the H:/mongodb

Thiyagesh
Guest
Thiyagesh

Hi mkyong,

I am very interested by the method of post…. reaching us. Very involving steps. Have installed and executed the service of mongodb in my maching. Thanks a Lot !!!

user z
Guest
user z

‘mongod’ is not recognized as an internal or external command,
operable program or batch file.

So what am I missing? It said set in windows environment but it didn’t say how.
A little more detail please?

Sateesh Smart
Guest
Sateesh Smart

Add the C:/mongodb/bin to you Environment paths

san
Guest
san

thanks for your explain, I was wonder how can I get the (mongo console) to play around with some commands

sekhar
Guest
sekhar

the clean explanation found so far on the subject. Thanks Yong!

Ali
Guest
Ali

very thnx mkyong

Ranjan Sai
Guest
Ranjan Sai

I am using Windows Vista, i have successfully installed and db is also open by using above command but while creating service using command

mongod –config D:mongodbmongo.config –install

it is successfully executing but when i am starting service using command
net start MongoDB
it is saying “The service name is invalid.”
What i did wrong??? Any suggestion

Sathya Prakash Moparthi
Guest
Sathya Prakash Moparthi

i finished installation using adnmin cmd prompt using
d:\mongodb\bin> mongod –config D:\mongodb\mongo.config –install

but when i type “net start MongoDB” prompt says “net” is not defined?

Hao Fu
Guest
Hao Fu

try run cmd as admin then try d:\mongodb\bin> mongod –config D:\mongodb\mongo.config –install

@_@
Guest
@_@

for{
fmt.Println(“Thanks”)
}

Abhi
Guest
Abhi

Hi mkyong,

I like your all the post.I am really eager to learn big data.If you have knowledge about this topic please post.

droidgirl
Guest
droidgirl

Thanks. Was able to set up Mongo Server and Client on 64bit Win7 following your tutorial.

Karthick Devaraj
Guest
Karthick Devaraj

Hi I am getting following error while starting mongodb,please help me anyone

JavaScript execution failed: Error: couldn’t connect to server 127.0.0.1:27017 at
mongo.js:L112
exception: connect failed

droidgirl
Guest
droidgirl

do you have your server running? I ran into the same error when the server wasn’t started properly.

trackback
MongoDB hello world example

[…] MongoDB on Windows, Ubuntu or Mac OS X. The installation is easy, basically just download the MongoDB zip file, extra […]

Aryan
Guest
Aryan

I tried installing based on your tutorial,
but it’s waiting for the connections on port 28017, but never terminating.
What to do now??
Please help me.
Thanks in advance.

Bhushan
Guest
Bhushan

getting below error while running mongod.exe from Windows 32 bit Cmd Prompt (I have downloaded 32 Bit Version of mongo db i.e. mongodb-win32-i386-2.2.0.zip)
“procedure entry point interlockedCompareExchange64 coluld not be located in
DLL KERNEL32.dll”

Amol
Guest
Amol
Nishant
Guest
Nishant

Hi,
During step 4 an error occurs saying Entry Point Not Found.
Please suggest me any solution.
Thanks in advance.

Jason
Guest
Jason

it keeps on saying waiting for connections on port 20817…I deleted mongod.lock and tried again but nothing happend, what should I do?

hari
Guest
hari

open another command shell and move to mongodb directory then bin and execute mongo.exe it will work

trackback
mongodb???? | ?????

[…] ??mongodb??http://www.mkyong.com/mongodb/how-to-install-mongodb-on-windows/,mongodb?????10????exe??,??????????????mongodb […]

trackback
Java MongoDB Tutorials

[…] Install MongoDB on Windows How to install MongoDB on Windows. […]

PM
Guest
PM

Do you plan on doing a series on MongoDB? Do you plan on using springData interface?