Updated February 28, 2023
Introduction to MongoDB Compass
MongoDB, one of the most widely used NoSQL Database, provides a GUI (Graphical User Interface), MongoDB Compass. MongoDB Compass allows you to interact actively and understand the data stored in MongoDB Database, without any prerequisite to have any knowledge of Coding or Shell Queries.
MongoDB Compass’s Connect Page:
Below is a screenshot of Compass’s Connect Page.
To connect the MongoDB Compass to the active MongoDB Instance, we have to fill in the above image’s details and then connect. It will connect the currently active instance of running MongoDB to the compass, and the data can be visualized.
Other than being able to read data, Compass allows you to present the data visually. Managing Indexes and the implementation of Document Validation is also effectively done by Compass.
Why do we Need MongoDB Compass?
Flexible schema and JSON like Document storage, provided by MongoDB, is a really great tool for developers to build applications over the database and work as a kind of obstacle to understand the structure of the database. You can certainly execute queries and understand the structure, but it was only possible for developers with MongoDB knowledge. But with MongoDB’s Compass, we now have multiple ways to understand the data and manipulate it without any knowledge of shell commands.
Introduced with MongoDB 3.2, Compass is a graphical tool to understand the data in an easy way and interact with the database without queries.
How does MongoDB Compass Work?
Basically, Compass is a GUI for what we have within our MongoDB Database. Every collection and documents can be reflected and manipulated. Every time we build and execute a query on the compass, it interprets the query into the command line query and executes it. Upon execution, whatever the result is, it reflects the result of the graphical visualization.
Features of MongoDB Compass
Basically, Compass itself is an advantage and a reason to use MongoDB. That being said, Compass comprises amazing features that make it more likely to be implemented for production uses. Let us now Define and understand every feature that compass offers:
1. Query
Creation and execution of queries can be done with the Compass interface. Aggregation Pipelines can be created and executed over the compass as easily as any normal query.
Example: In the below image, we have created a simple query to find records or documents, which consists of Pune as a city, and as a result, we have 2 records.
This is equal to db.educba.find() query on the shell.
2. Indexes
Just like queries and aggregation pipelines can be created and executed with a compass, Creating and Deleting Indexes for MongoDB Collection, is easy with Compass. In the following screenshot, we have three indexes that already exist.
Here we have a “CREATE INDEX” Button, which is used to create indexes. Then we have a list of our indexes, for Name, _id, and email. One important thing here is that except _id all other indexes can be deleted because _id index is default and automatically created when we insert a single record. Rest, we have all other details surrounding the index.
3. Rules
Along with Documents, we have Document Validation Rules, which can be created, edited, and deleted, from the compass.
4. Interaction
Without Compass, the only way to interact with Databases, Documents and Collections was with the MongoDB Shell, with Commands. But with Compass out in the market for usage, it has been tremendously easier for non-technical persons to interact with the database. CRUD Functionalities, which means Create, Read, Update, and Delete, can be executed, data can be easily manipulated. In the below screenshot, we are attempting to edit the value for one of the keys. The Name key will be updated here, instead of executing a db, update query.
5. Reporting
To report and analyze, any unusual event or errors or bugs, is an important part of any database or a system, in order to improve. Crash reporting is done effectively in Compass, along with collecting error logs and steps to improvise.
6. Explain
We have an Explain Plan Tab with MongoDB Compass, which reflects the execution plan for a query. Refer below the image for better understanding.
Simply, fill in the query and click on explain. It will then fetch every detail related to that query like Documents Returned, Execution Time, Documents examined, and several index keys examined.
7. Schema
Compass provides you with a better way to visualize your schema, helps you to analyze the document. It supports exploring the schema to understand the types and frequency of the data set. This is an important feature, as we know that MongoDB has a different flexible schema. Start by typing in a query, modify if necessary and then apply, this will go deep into the database or the respective collection and fetch the matching documents. Upon successful, fetching operation, it will present the data in a visual format. Refer to the below screenshot for proper output.
Upon executing, it returns every aspect of the query, which is the number of documents fetched, then we have the keys, meaning “_id, city, loc”, which defines the documents. Most of the analytical insights regarding the document, data, and the query can be learned from the schema Analysis.
8. Performance
Compass is one of the best ways to analyze the data and performance of the database. With the help of visual plans, performance for queries can be viewed and optimized, too.
Advantages and Disadvantages
Following are the advantages and disadvantages of using MongoDB Compass:
Advantages
- Easy to Use, Simple GUI.
- Query Building and Executing.
- Reporting.
- Performance Analysis.
- Monitoring Indexes.
These advantages make the MongoDB Compass better equivalent to use when interacting with MongoDB Data.
Disadvantages
Basically, Compass is all in one great tool. With stable updates, the Compass is being improved regularly. Free to Use but Limited Features.
Conclusion
To wrap it up, MongoDB Compass is easy to use, GUI, a simple tool to analyze the data stored in the collections. Features like Indexing, Performance, Query and Aggregation Pipeline Building and many more advantages, makes this tool easy to use. Compass is a great tool to understand and manipulate the data for any person without any knowledge of command-line queries.
Recommended Articles
This is a guide to MongoDB Compass. Here we also discuss the Introduction and how does MongoDB compass work? Along with features, advantages, and disadvantages. You may also have a look at the following articles to learn more –