What is MongoDB Compass: The Ultimate Guide

on Database Management Systems, MongoDB • February 9th, 2022 • Write for Hevo

MongoDB Compass

Today, a colossal amount of unstructured data is being generated within organizations. However, handling unstructured data is not as straightforward as structured data. Consequently, organizations need better data management tools to work effectively with unstructured data. While organizations can leverage command interfaces, it requires expertise in interacting with servers. Such workflows can limit organizations from harnessing the power of unstructured data effectively.

To mitigate such challenges, organizations can leverage MongoDB Compass, a Graphical User Interface solution that can assist any user in Creating, Inserting, Updating, Filtering, and even Deleting the documents visually with a click of the buttons. Besides, it becomes complex to query extensive volume data in the command-line interface. The speed of the MongoDB Shell can decrease while processing massive data. Further, the MongoDB Shell works on the database on its own, and users cannot analyze and see the data changes independently. In contrast, in MongoDB Compass, users can visualize their database and its modifications without worrying about the performance.

Table of Contents

Prerequisites

  • Understanding of unstructured data.

What is MongoDB?

MongoDB Compass: MongoDB Image
Image Source

MongoDB is an open-source unstructured database that allows users to store data in key-value pairs, making it easy to access. Since it is an unstructured database, it has a flexible data structure that makes it easier to use for systems with a large volume of data and high performance.

The data in MongoDB is referred to as Documents, whereas the number of Documents is called a Collection. Each document in the MongoDB Collection is different due to its unstructured format. Consequently, MongoDB is called a schema-less database. MongoDB environment provides a MongoDB Server to start and create several databases.

What is MongoDB Compass?

MongoDB Compass: MongoDB Compass Image
Image Source

MongoDB allows users to interact with the MongoDB Server through two interfaces. The first one is the Mongo shell, which is the simple command-line interface of the MongoDB server.

The other one is the Graphical User Interface (GUI) that allows users to communicate with the MongoDB Server through automated tool functions rather than command-line queries. One such GUI tool is MongoDB Compass, which is used to query and analyze MongoDB data visually.

MongoDB Compass is open-source and is available for operating systems like Linux, Windows, macOS, etc. MongoDB Compass is a perfect alternative to the MongoDB Shell as it is not feasible to carry out complex queries with the MongoDB Shell.

Simplify your MongoDB ETL with Hevo’s No-code Data Pipeline

A fully managed No-code Data Pipeline platform like Hevo helps you integrate data from 100+ data sources (including 40+ Free Data Sources) like MongoDB to a destination of your choice in real-time in an effortless manner. Hevo with its minimal learning curve can be set up in just a few minutes allowing the users to load data without having to compromise performance. Its strong integration with umpteenth sources provides users with the flexibility to bring in data of different kinds, in a smooth fashion without having to code a single line. 

GET STARTED WITH HEVO FOR FREE

Check Out Some of the Cool Features of Hevo:

  • Completely Automated: The Hevo platform can be set up in just a few minutes and requires minimal maintenance.
  • Real-Time Data Transfer: Hevo provides real-time data migration, so you can have analysis-ready data always.
  • Transformations: Hevo provides preload transformations through Python code. It also allows you to run transformation code for each event in the Data Pipelines you set up. You need to edit the event object’s properties received in the transform method as a parameter to carry out the transformation. Hevo also offers drag and drop transformations like Date and Control Functions, JSON, and Event Manipulation to name a few. These can be configured and tested before putting them to use.
  • Connectors: Hevo supports 100+ Integrations to SaaS platforms, files, databases, analytics, and BI tools. It supports various destinations including Amazon Redshift, Firebolt, Snowflake Data Warehouses; Databricks, Amazon S3 Data Lakes; MongoDB, MySQL, SQL Server, TokuDB, DynamoDB, PostgreSQL databases to name a few.  
  • 100% Complete & Accurate Data Transfer: Hevo’s robust infrastructure ensures reliable data transfer with zero data loss.
  • Scalable Infrastructure: Hevo has in-built integrations for 100+ sources, that can help you scale your data infrastructure as required.
  • 24/7 Live Support: The Hevo team is available round the clock to extend exceptional support to you through chat, email, and support calls.
  • Schema Management: Hevo takes away the tedious task of schema management & automatically detects the schema of incoming data and maps it to the destination schema.
  • Live Monitoring: Hevo allows you to monitor the data flow so you can check where your data is at a particular point in time.
GET STARTED WITH HEVO FOR FREE

How To Use MongoDB Compass?

A) Install the MongoDB Server

To start with the MongoDB Compass, you need to download the MongoDB Server and install it. You can download the latest version of MongoDB Server from the official page.

This tutorial uses the Windows 7 Operating System, but you can use any operating system. To install MongoDB on your system, follow the below steps.

  • Step 1: Open the Installation Setup.
MongoDB Compass Setup Step 1
Image Source
  • Step 2: Click on the Next button.
MongoDB Compass Setup Step 1.2
Image Source
  • Step 3: You need to accept the agreement and click Next.
MongoDB Compass Setup Step 1.3
Image Source
  • Step 4: Click on the complete setup option as shown above.

B) Install the MongoDB Compass

To download the MongoDB Compass, follow the below steps:

  • Step 1: Download MongoDB Compass. Choose the Community Edition Stable version from the drop-down menu.
  • Step 2: Select Windows 7 Operating System and click on the Download button.
  • Step 3: Launch the MongoDB Compass Installer, accept the agreement and click on Start using Compass. 
MongoDB Compass Setup Step 2.1
Image Source
  • Step 4: You have to set up the GUI software and connect it to the MongoDB instance. Set the parameters as mentioned below:
    • Hostname as Localhost.
    • Port as 27017.
    • Click on connect as the rest of the fields are default.
  • Step 5: After clicking on connect option, you will see a screen similar to the below image.
MongoDB Compass Setup Step 2.2
Image Source

C) Create a Database and Insert data in MongoDB Compass

  • Step 1: Go to the Create Database button, as shown above. It loads the database helper window, as shown below.
MongoDB Compass Setup Step 3.1
Image Source
  • Step 2: From above, you need to specify the name of the Collection and database created and then click on the Create Database button. The database name is ‘peopledb’ and the collection name is ‘people’ , as you can see below:
MongoDB Compass Setup Step 3.2
Image Source
  • Step 3: Click on the ‘people’ tab available on the left-hand side under the cluster tab.
  • Step 4: Click on the Documents section. You can see the below window.
MongoDB Compass Setup Step 3.3
Image Source
  • Step 5: After you click on the Insert Document, it opens an Insert Document Helper, as shown below:
MongoDB Compass Setup Step 3.4
Image Source
  • Step 6: In MongoDB Compass, you can Insert Documents in two types:
    • Import JSON or CSV file.
    • Insert data manually.
  • Step 7: Go to the Add Data option. It gives you two options to import or insert data manually. If you want to import a CSV or JSON file, click on import, it will show the below window.
MongoDB Compass Setup Step 3.5
Image Source
  • Step 8: You need to browse the file, select the file type, and import it. It should be in the pair of keys and values when you add data manually, as shown below.
MongoDB Compass Setup Step 3.6
Image Source
  • Step 9: You need to view the inserted data. In MongoDB Compass, you can view the data in two formats: List and Table View. Go to ‘peopledb’ in the left-hand side corner and click on the Collection named ‘people’. You can see the following window:
MongoDB Compass Setup Step 3.7
Image Source
  • Step 10: From above, you can see documents in the ‘people’ Collection are by default in the list view. You can change it to Tables through the option given there. Click on the Table option, and you will get the following screen.
MongoDB Compass Setup Step 3.8
Image Source

D) Update and Delete Documents in MongoDB Compass

After Creating and Inserting a Document, you need to know how to Update the Document. To update the Document, follow the below steps:

MongoDB Compass Setup Step 4.1
Image Source
  • Step 1: You can see from above that the modification is enabled, and you can update any document you want. After modifying, you need to click on the Update button below.
MongoDB Compass Setup Step 4.2
Image Source

Similar to Updating, you can also Delete documents in MongoDB Compass.

  • Step 2: Go to the document you want to delete; you can see the trash icon as shown in the below window.
MongoDB Compass Setup Step 4.3
Image Source
  • Step 3: Click on the Trash icon. You can see the red notification mentioning that the document has been deleted.
MongoDB Compass Setup Step 4.4
Image Source

E) Query Documents in MongoDB Compass

After creating, inserting, updating, and deleting the document, you also need to query the document. To query the documents follow the below steps:

  • Step 1: Go to the left-hand side of the MongoDB Compass and select the inventory collection. If you want to select all the documents in the collection, you pass an empty query filter {} to the filter input and click on find.
MongoDB Compass Setup Step 5.1
Image Source

From above, you can see that all documents in the collection are selected. 

  • Step 2: To query a document that matches a particular condition, you need to raise the query in the key-value format like { status: “D” }.
MongoDB Compass Setup Step 5.2
Image Source

From above, you can see that all the documents having status as “D” are filtered by the query.

  • Step 3: If there is an embedded document, you need to specify the exact values in the query to filter that document. For example, { size: { h: 14, w: 21, uom: “cm” } }. The field size has the specified value in it, you need to add a query giving the exact values. Check the below window.
MongoDB Compass Setup Step 5.3
Image Source

You can see from the above window that the document having the { h: 14, w: 21, uom: “cm” } value is fetched by the query.

  • Step 4: You can also match only a specified field in the embedded document. You have to enter the query { “size.uom”: “in” }.  It fetches all the documents containing that field, just as shown below.
MongoDB Compass Setup Step 5.4
Image Source

From above, all the documents having { “size.uom”: “in” } are selected and fetched.

  • Step 5: You can also match the element in an array using the query { tags: “red” }.
MongoDB Compass Setup Step 5.5
Image Source

From above, you can see the query { tags: “red” } fetched all the documents with tags containing the string “red.”

Conclusion

This tutorial lets you get familiar with MongoDB Compass, a GUI tool that enables users to visualize the MongoDB Database. You can create, insert, update and delete documents in databases with straightforward options rather than writing manual queries in MongoDB Compass.

It helps users in activities like Indexing and Document Validation. In this tutorial, you have used MongoDB compass on operations like insert, delete, and querying documents with filter and find features. You can also explore the other features of MongoDB Compass like Index Management, Server’s real-time performance metrics or Server Statistics, Query Execution Visualization, and more.

Extracting complex data from a diverse set of data sources to carry out an insightful analysis can be challenging, and this is where Hevo saves the day! Hevo offers a faster way to move data from Databases or SaaS applications like MongoDB into your Data Warehouse to be visualized in a BI tool. Hevo is fully automated and hence does not require you to code.

GET STARTED WITH HEVO FOR FREE

If you are using MongoDB as a source of data and searching for a no-fuss alternative to Manual Data Integration, then Hevo can effortlessly automate this for you. Hevo, with its strong integration with 100+ sources & BI tools (Including 40+ Free Sources), allows you to not only export & load data but also transform & enrich your data & make it analysis-ready in a jiffy.

Sign up for a 14-day free trial and simplify your Data Integration process. Do check out the pricing details to understand which plan fulfills all your business needs.

No-code Data Pipeline for MongoDB