w3resource logo


Install Mongodb Winsdows

Install MongoDB on Windows

Secondary Nav

Download

Pre-built binary packages of MongoDB are available for both 32 bit and 64 bit. You can download it, and install.

Here is the link to download pre-built binary packages of MongoDB : http://www.mongodb.org/downloads

mongodb download windows

Unzip

After downloading the zip file, unzip it to the folder where you want to install.

Create a data directory

MongoDB stores data in db folder within data folder. But, since this data folder is not created automatically, you have to create it manually. Remember that data directory should be created in the root (i.e. C:\ or D:\ or so).

For this tutorial, we have unzipped it within mongodb folder within D: drive. Now, we will create a folder called data and within that we will create a folder called db.

mongodb installation windows

It is not necessary to perform the above operation from the command prompt. You may opt to do this from Windows Explorer also.

Run the MongoDB server from command prompt

To run MongoDB server from the command prompt, you have to execute mongod.exe file from bin folder of mongodb folder.

mongodb run windows command

Run the MongoDB server as a windows service

Remember that you must have administrative privilege to run the following command. Run the following command to install MongoDb as a Windows Service :

mongod --bind_ip yourIPadress --logpath "C:\data\dbConf\mongodb.log" --logappend --dbpath "C:\data\db" --port yourPortNumber --serviceName "YourServiceName" --serviceDisplayName "YourServiceName" --install

The following table shows what does different arguments specify :

Arguments Description
--bind_ip Specify your IP address following this.
--logpath Specify the file of the logfile following this.
--logappend Specify this so that logs are appended to the log file.
--dbpath Specify the path of the db folder within data folder.
--port Specify the port you want to use. Default port is 20127. If this argument is not specified, default port is used.
--serviceName Specify the service name you want to opt for, following this.
--serviceDisplayNam Specify the service name you want to opt for, following this, if you have more than one MongoDB services running.
--install Specify this to install MongoDB as a Windows Service.

Getting started with administrative shell

To start an administrative shell, enter bin directory of your MongoDB installation and execute mongo.exe file. The default administrative shell of MongoDB is a JavaScript shell. When you connect MongoDB immediately after installation, it connects to the test document (database).

run mongo shell

Since it is a JavaScript Shell, you can run some simple arithmetic operation.

run mongo shell2

db command will show you the list of documents(databases).

run mongo shell db command

We will insert a simple record and retrieve the data now.

mongo first find

The first command inserts 10 to the x field, to the w3r collection(table)



Join our Question Answer community to learn and share your programming knowledge.