MongoDb - Install MongoDb on Windows

 

Install MongoDb on Windows

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 command prompt. You may opt to do this from Windows Explorer also.

Run the MongoDb server from command prompt

To run MongoDb server from 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 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)

?

Source: http://www.w3resource.com/mongodb/installation-windows.php