How to Use MongoDB Compass

MongoDB Compass is a powerful GUI that accesses your database engine through an intuitive visual display. Sometimes, a command-line interface isn’t ideal for database work. In that case, MongoDB Compass (or Compass for short) can make finding and analyzing data easier. As a visual tool, you can view, manipulate, and analyze data, with most of MongoDB’s features readily accessible.

After you understand how to use it, you can comb through MongoDB databases, collections, and individual documents. Also, you can create queries, manipulate existing documents, and design aggregation pipelines from a single interface.

Here is a tutorial on how to use MongoDB Compass as a database administration tool.

Download Compass

The first step is to download Compass to your computer. It is free to use and can be run on macOS, Windows, or Linux. Installing Compass requires MongoDB 4.2 or later. Windows users also need the .NET Framework version 4.5 or later.

Connect to MongoDB

MongoDB Compass can connect to a MongoDB host as a standalone, replica set or sharded cluster host. You’ll need the details specific to your MongoDB setup to establish a connection, including hostname, port, and credentials.

If you don’t already have a MongoDB host, MongoDB Atlas is one option. This cloud-hosted database requires no installation, has a free tier, and provides a copyable URL to connect Compass to your deployment.

Customize the MongoDB Compass

You can customize the Compass settings, tailoring the interface to your needs. For instance, you can adjust the visual appearance of Compass, including font size, themes, and layout preferences. Also, define user roles and permissions to control access to data and functionalities. You can configure privacy settings to manage how Compass handles your connection information.

Compass provides options to launch and configure the application through the command line, offering greater control for tech-savvy users. Additionally, a configuration file allows you to specify various settings for Compass startup and behaviour.

Other customization options include:

  • Block outgoing network connections.
  • Hide credentials from your connection string.
  • Restrict write operations to MongoDB.
  • Specify read preferences and tags.
  • Toggle Chrome DevTools.

Import Your Data into MongoDB Compass

To explore Compass, you need a data set. To import data, connect to a MongoDB deployment hosted on MongoDB Atlas. Alternatively, you can deploy to a local host on your machine if you aren’t connected to the network. Data can be uploaded in CSV or JSON files.

Create and Insert Data into MongoDB Compass

Use the Create Database button to initiate database creation. A crucial step is assigning an appropriate name to your database in the designated field of the opened window. Confirm the creation is done by clicking the Create button.

After creating the database, you need to define a collection within it to store your data. Click on InsertDocument, which will show the next steps. You can then specify the collection name and insert data using various methods. If you aren’t importing, you can manually enter the data at this stage.

Query Your Data in Compass

The left-hand side of Compass allows you to select an inventory collection. You can pass an empty query filter to the filter input and click on Find. To query a document for a particular condition, raise the query in the key-value format, such as { status: “D” }, which filters results for any with a status of “D”

You can also match only a specified field in the embedded document, fetching all documents containing that field. There are many ways to query data and draw information from those queries.

Exporting Queries to Specific Languages

Export queries created in MongoDB Compass can be done in various supported languages. These are Java, Node, C#, Python 3, Ruby, Go, Rust, or PHP. You can then reformat and use MongoDB Compass queries in your application by exporting.

Update and Delete Documents in Compass

MongoDB Compass allows you to update existing documents in your collections. First, locate the document you want to modify. Next, open the editor and make your changes. Once the changes have been made, save them.

Documents can also be deleted. To do this, find the document in the collection. Right-click to bring up a context menu. After selecting delete, Compass will prompt confirmation before permanently
removing the document.

Interact with Your Data in MongoDB Compass

MongoDB Compass interactions are fairly straightforward. You can manage documents, query data, or launch queries in natural language. Other functionalities include managing indexes, analyzing data schemas, setting validation rules for your schema, sampling, and more. You can follow tutorials on specific actions to take with Compass, guiding users who may be stuck.

Create Aggregation Pipelines

Author aggregation pipelines allow documents in a collection or view to pass multiple stages as they are processed into aggregated results.

There are several ways to do this. Stage View Mode preloads pipeline syntax based on your selected stages. Another is the Stage Wizard (found in View Mode), which provides an easy set of templates for simple aggregation stage use cases.

Focus Mode edits one pipeline stage at a time, which helps manage more complex or deeply nested aggregation pipeline stages. Lastly, Text View Mode is a text-based pipeline editor that accepts raw pipeline syntax.

Run Commands in the Shell

After connecting to a deployment, you can interact with your data using the MongoDB Shell within Compass. This shell allows you to execute commands for data manipulation and database management.

Review Compass Home

Compass Home is your main screen, providing details about the connection. You can see the connection name, any saved queries or aggregation pipelines, and a list of databases. You can also monitor performance statistics, from memory usage to operation counts.

Everything here can be reviewed regularly to analyze key data. For example, learn which database collections receive the most operations. Likewise, understand which operations take the longest to execute. It is also possible to analyze memory utilization. These insights guide you on what needs to change or if there is any trouble with your database performance.

Troubleshooting MongoDB Compass

To troubleshoot Compass, examine the logs. All events are recorded. Compass logs will provide you with a history of operations and diagnose errors.

The log files can be accessed through the Compass top bar menu under “Help” Click Open Log File by copying the path to your clipboard, opening the folder with the log file, or extracting it and viewing it as a text file.



Sudeep Bhatnagar
Co-founder & Director of Business
Sudeep Bhatnagar

Talk to our experts who have been running successful Digital Product Development (Apps, Web Apps), Offshore Team Operations, and Hardcore Software Development Campaigns. During the discovery session, we'll explore the opportunities and Scope of the work and provide you an expert consulting on the right options to achieve the outcomes.

Be it a new App Development project, or creation of an offshore developers team, or digitalization of your existing market offerings - You'll get the best advise and service and pricing. We are excited to speak to you!

Book a Call

Let’s Create Big Stories Together!

Mobile is in our nerves. We don’t just build apps, we create brands.

Choosing us will be your best decision.

Relevant Blog Posts