Install MongoDB With Compass On Windows

install and configure mongodb

MongoDB is a database system that stores data in flexible, JSON based documents, which means fields can vary from document to document and data structures can be changed over time. This is quite different than how traditional relational databases work such as MySQL. The document model in Mongodb maps to the objects in the application code. This makes the data more seamless and easier to work with. You are simply working with objects, and they have persistence via Mongodb. MongoDB is free and open-source and scales well for almost any project. The key takeaway is that with Mongodb, it is JSON objects in, and JSON objects out of the database. There is no transformation of data like in SQL based systems.

Installing MongoDB on Windows

Now we can install Mongodb on our computer to test out some of it’s features. On the downloads section of the Mongodb website, we can choose the community server edition for Windows and click the download button to get a copy of the installation package. Once you have the installer on your computer, go ahead and run the installation.
mongodb setup wizard windows

When you see the option to include Compass as part of the installation, leave this unchecked. You may run into an error such as “Installation ended prematurely” if you leave this checked. This might be a bug with the installer.
leave install mongodb compass unchecked

This should allow you to complete the installation fully. Once it is complete, we do want to install the Compass tool however.

Install Compass For MongoDB

Compass in Mongodb is analogous to phpmyadmin for MySQL. It is a graphical tool that makes working with the database easier. Navigate back to the download center at the MongoDB website and choose the Compass tab. Select Windows and click download.
install mongodb compass gui tool

Go ahead and run the installer file and you ‘ll see something like this.
mongodb compass is being installed

Once complete, the Compass application will launch and you’ll see some welcome messages.
mongodb compass is now installed

Add MongoDB Environment Variable To The Path

The last thing we want to do is to add the folder which holds the Mongodb executable to the system path. Here is how to do it.

Visit the advanced system settings.
windows 10 advanced system settings

Once there, choose the Environment Variables button.
click on environment variables

Select the Path and choose Edit.
click edit to update the path

Click New, and add the path to the MongoDB installation folder. Click OK a few times and you’re good.
click new and add the path to mongodb

Create The Folder To Hold Data

We are almost home! The last thing we need to do is to add the folder where MongoDB is going to store data. This is located at C:\data\db\ by default. Go ahead and create that folder on your machine now.

Awesome! You are ready to work with MongoDB!

At a command prompt type mongod and hit enter. You should see a bunch of information in the terminal, but the final and important message you want to see is: “waiting for connections on port 27017”
waiting for connections on port 27017
This means the the Mongo Database is up and running and ready for use. We can now use the Compass GUI to connect to the server. Let’s try it out!
connect to mongodb with compass gui

Once it connects, you will see something like this.
mongodb compass is now connected to mongodb

Install MongoDB With Compass On Windows Summary

It takes a few steps to get everything working on a local machine so you can work with MongoDB and Compass the associated GUI. As you saw, it’s not too bad to complete the installation. The great thing is we are now ready to start working with Node.js as the server and MongoDB as the database along with the Express Framework to start building some cool applications.

Some Key Points To Remember

  • MongoDB is an open source document database (NoSQL).
  • MongoDB stores data in flexible, JSON like documents.
  • Relational databases have tables and rows, unlike MongoDB.
  • MongoDB uses collections and documents.
  • A document can contain sub-documents.
  • Traditional relationships do not exist between documents.