How to Download and Install MongoDB on Windows

In the article, we discuss about How to Download and Install MongoDB on Windows

How to Download & Install How to Download and Install MongoDB on Windows

How to Download and Install MongoDB on Windows
How to Download and Install MongoDB on Windows

How to Download and Install MongoDB on Windows

The installers for MongoDB are available in both the 32-bit and 64-bit formats. The 32-bit installers are good for development and test environments. But for production environments, you should use 64-bit installers. Otherwise, you can be limited to the amount of data that can be stored within MongoDB.

It is advisable to always use the stable release for production environments.

  • Download & Install MongoDB on Windows
  • Hello World MongoDB: JavaScript Driver
  • Install Python Driver
  • Install Ruby Driver
  • Install MongoDB Compass- MongoDB Management Tool
  • MongoDB Configuration, Import and Export
  • Configuring MongoDB server with configuration file

How to Download & Install MongoDB on Windows

The following steps can be used to download and install MongoDB on Windows 10

Step 1) Download MongoDB Community Server

Go to link and Download MongoDB Community Server. We will install the 64-bit version for Windows.

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Step 2) Click on Setup

Once download is complete open the msi file. Click Next in the start up screen

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Step 3) Accept the End-User License Agreement

  1. Accept the End-User License Agreement
  2. Click Next

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Step 4) Click on the “complete” button

Click on the “complete” button to install all of the components. The custom option can be used to install selective components or if you want to change the location of the installation.

Step 5) Service Configuration

  1. Select “Run service as Network Service user”. make a note of the data directory, we’ll need this later.
  2. Click Next

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Step 6) Start installation process

Click on the Install button to start the installation.

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Step 7) Click Next once completed

Installation begins. Click Next once completed

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Step 8) Click on the Finish button

Final step, Once complete the installation, Click on the Finish button

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Hello World MongoDB: JavaScript Driver

The driver for JavaScript comes out of the box. The MongoDB shell which is used to work with MongoDB database is actually a javascript shell. To access it

Drivers in MongoDB are used for connectivity between client applications and the database. For example, if you had Java program and required it to connect to MongoDB then you would require to download and integrate the Java driver so that the program can work with the MongoDB database.

Step 1) Go to ” C:\Program Files\MongoDB\Server\4.0\bin” and double click on mongo.exe. Alternatively, you can also click on the MongoDB desktop item

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Step 2) Enter following program into shell

var myMessage='Hello World';
printjson(myMessage);
How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Code Explanation:

  1. We are just declaring a simple Javascript variable to store a string called ‘Hello World.’
  2. We are using the printjson method to print the variable to the screen.

Install Python Driver

Step 1) Ensure Python is installed on the system

Step 2) Install the mongo related drivers by issuing the below command

pip install pymongo

Install Ruby Driver

Step 1) Ensure Ruby is installed on the system

Step 2) Ensure gems is updated by issuing the command

gem update -system

Step 3) Install the mongo related drivers by issuing the below command

gem install mong

Install MongoDB Compass- MongoDB Management Tool

There are tools in the market which are available for managing MongoDB. One such non-commercial tool is MongoDB Compass.

Some of the features of Compass are given below:

  1. Full power of the Mongoshell
  2. Multiple shells
  3. Multiple results

Step 1) Go to link and click download

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Step 2) Enter details in the popup and click submit

Step 3) Double click on the downloaded file

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Step 4) Installation will auto-start

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Step 5) Compass will launch with a Welcome screen

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Step 6) Keep the privacy settings as default and Click “Start Using Compass”

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Step 7) You will see homescreen with list of current databases.

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

MongoDB Configuration, Import, and Export

Before starting the MongoDB server, the first key aspect is to configure the data directory where all the MongoDB data will be stored. This can be done in the following way

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

The above command ‘md \data\db’ makes a directory called \data\db in your current location.

MongoDB will automatically create the databases in this location, because this is the default location for MongoDB to store its information. We are just ensuring the directory is present, so that MongoDB can find it when it starts.

The import of data into MongoDB is done using the “mongoimport” command. The following example shows how this can be done.

Step 1) Create a CSV file called data.csv and put the following data in it

Employeeid,EmployeeName

  1. thestackoverflow
  2. Mohan
  3. Smith

So in the above example, we are assuming we want to import 3 documents into a collection called data. The first row is called the header line which will become the Field names of the collection.

Step 2) Issue the mongo import command

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Code Explanation:

  1. We are specifying the db option to say which database the data should be imported to
  2. The type option is to specify that we are importing a csv file
  3. Remember that the first row is called the header line which will become the Field names of the collection, that is why we specify the –headerline option. And then we specify our data.csv file.

Output

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

The output clearly shows that 3 documents were imported into MongoDB.

Exporting MongoDB is done by using the mongoexport command

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Code Explanation:

  1. We are specifying the db option to say which database the data should be exported from.
  2. We are specifying the collection option to say which collection to use
  3. The third option is to specify that we want to export to a csv file
  4. The fourth is to specify which fields of the collection should be exported.
  5. The –out option specifies the name of the csv file to export the data to.

Output

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

The output clearly shows that 3 records were exported from MongoDB.

Configuring MongoDB server with configuration file

One can configure the mongod server instance to startup with a configuration file. The configuration file contains settings that are equivalent to the mongod command-line options.

For example, supposed you wanted MongoDB to store all its logging information to a custom location then follow the below steps

Step 1) Create a file called, “mongod.conf” and store the below information in the file

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows
  1. The first line of the file specifies that we want to add configuration for the system log file, that is where the information about what the server is doing in a custom log file.
  2. The second option is to mention that the location will be a file.
  3. This mentions the location of the log file
  4. The logAppend: “true” means to ensure that the log information keeps on getting added to the log file. If you put the value as “false”, then the file would be deleted and created fresh whenever the server starts again.

Step 2) Start the mongod server process and specify the above created configuration file as a parameter. The screenshot of how this can be done is shown below

How to Download & Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Once the above command is executed, the server process will start using this configuration file, and if you go to the /etc. directory on your system, you will see the mongod.log file created.

The below snapshot shows an example of what a log file would look like.

How to Download and Install MongoDB on Windows
How to Download and Install MongoDB on Windows

Source: GURU99

Also Check out Build a URL Shortener with XpresserJs Using MongoDB

If you interested in Entertainment genre please check this also Deepika Padukone Age, Biography, Wiki, Family, Filmography & More

MongoDB, MongoDB Compass, MongoDB install windows, MongoDB compass install on windows, MongoDB configuration in windows, MongoDB setup in windows 10

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

How to Protect yourself from CovidVaccination saves lives at every stage of life
  • Clean your home regularly, particularly frequently touched surfaces like
  • Stay home stay safe. Follow the Golden Rule. Wash your hands frequently with soap and water or use alchohol based hand-rub.
  • Stay home stay safe. Stay physically fit. Exercise regulary. Eat a nutritious diet. Don’t smoke.
  • Stay home stay safe. If you show symptoms of COVID-19, self isolate yourself, wear a mask around others and seek medical advice