HOW TO INSTALL AND RUN MONGO DB ON WINDOWS 10
Tags: mongodb, codenewbie, 100daysofcode, javascript
Published: 2021-04-10 08:10:27

This article was initially published on [Hashnode](https://koladechrisksound.hashnode.dev/how-to-install-and-run-mongo-db-on-windows-10)

MongoDB is a NoSQL database that has gained popularity in recent times. Unlike SQL databases that are like advanced spreadsheets, MongoDB stores data in JSON-like key-value pair called BSON (Binary JSON) in order to support features JSON does not.
 
In this article, I will walk you through the step-by-step guide on how to install MongoDB on your Windows 10 operating system, with insights on GUI tools such as Mongo Compass and Robo 3t.

#### **INSTALLING MONGO DB**

**STEP 1**: First of all, you need to download MongoDB from the official website. You can do that  [here](https://www.mongodb.com/try/download/community). Make sure you select msi as the package type and not zip. 
Follow the installer wizard to install MongoDB. 
![1 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618035008165/aeC1dL-UH.png)


![2 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618035127317/fpukrXTYr.png) Select Complete as your setup type and keep the next item on default.


![3 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618035248873/TSAWENkjF.png)
You can choose to install Mongo Compass here; it would just take more time to install everything. My preference is to uncheck the box so I can download and install it separately.


![4 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618035362014/j34ITcUlj.png)
Click install. 

**STEP 2**: Once it is done installing, navigate to `C:/ProgramFiles/MongoDB/Server/4.4/bin`. There, you should find Mongo.exe, mongod.exe, and mongos.exe. They are Mongo, MongoDB, and Mongo shell respectively.


![5 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618035664890/EmxHD_hcx.png)

![6 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618035804090/lLaJkv8Ui.png)

**STEP 3**: Click on the address bar and type cmd to launch your windows command prompt. Click on enter and run `mongo --version`. You will see the version of the MongoDB installed. This means MongoDB has been rightly installed on your machine.


![7 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618035857498/OwQOG7eFv.png)
In my case, it is version 4.4.4.

**STEP 4**: Next, close the command prompt and launch it in no directory this time. Run `mongo --version`. The response is “mongo is not recognized as an internal or external command operable program or batch file. Chill. This is because your path variable has not been assigned, meaning you have to set environment variables on your machine.

**STEP 5**: Search for "environment" on your machine and click “Edit the system environment variables”. You can find this in the control panel too.

![8 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618036007471/ZmOpEOal5.png)

**STEP 6**: Click on environment variables.


![9 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618036100402/mBW_MK3W8.png)

**STEP 7**: Under system variables, select path and click on edit.

**STEP 8**: In the next pop-up, click on New in order to paste your installation path. Go back to the directory where you got a proper installation response and copy the address.

![10 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618036213773/J26AQW7R4.png)

**STEP 9**: Click on New again and paste the address you copied. Hit Enter and continue clicking OK until all the boxes are closed.


![11 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618036307325/b_cT3Hesn.png)


![12 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618036438131/Ff232pkzV.png)

**STEP 10**: Now, close your command prompt. Relaunch it and run the `mongo --version`. This time you should get a proper response that MongoDB has been installed correctly. Run `mongod --version` too to make sure the database is installed.
Forgive me for switching to Git Bash. I like to use it or Windows Subsystem for Linux (WSL).

#### **CONNECTING AND RUNNING MONGO DB**
**STEP 1**: To connect your command line to MongoDB, type mongo and hit enter.
If everything is done correctly so far, the mongo server should be running on port 27017 by now.


![13 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618037631213/GBxSStQsM.png)

**STEP 2**: To start using MongoDB, start by checking MongoDB default databases by running `show dbs`.

**STEP 3**: To create a database, run `use firstDB`. You can give it whatever name you want.

**STEP 4**: To create a collection, run `db.<collection-name>.insert({“anything you want”: "anything you want"})`. Feel free to add more.  To show your collection, run `show collections`; your collection should show.
 
**STEP 5**: Run `show dbs` again to see the databases on your machine; you should see the database you created in **step 3** above.


![14 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618037665531/walKOu_PP.png)

#### **USING THE GUIs**
To use the Mongo Compass GUI, download it  [here](https://www.mongodb.com/try/download/compass). Make sure you select the right platform for windows.
Install it, it is straightforward. Launch the Mongo compass and you should see the interface below.


![15 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618038139625/v9a91Ra5w.png)

You might have to make some simple selections in order to see the interface above.
To connect the Mongo Compass to MongoDB, click “Fill in collection fields individually”.


![16 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618038208735/aJ0LChKbh.png)

Leave everything the way it is and click connect and you should see the databases available on your computer.

![17 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618038309690/rnt_XWpLFO.png)

Here, you can create, insert, read, update and delete without the command line. Once you do it here, it's done globally, so if you check your collection again in the command line by running `db.<collection-name>.find()`, you see what you’ve done in the GUI.


![18 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618038425906/yXKieOzlo.png)

If you have ever used Mongo Atlas (MongoDB in the cloud), the interface is very similar to the one you see above.

As for Robo 3t, a third-party GUI tool, you can download it  [here](https://robomongo.org/download). 
It's simple to connect too and easier to work with than Compass, but I prefer Compass because of the Atlas-like interface.

![19 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618038771879/uH16LRv8N.png)

As you can see above, I have inserted my middle name and nickname with Robo 3t.


![20 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618038953887/CqT9wf17h.png)
Checking my database with `db.person.find()` gave me what you see above.

Thank you for reading.

Connect with me via my  [portfolio site](https://ksound22.github.io/), and Twitter via  [@koladechris](https://twitter.com/koladechris/), where I tweet and engage in anything web development.