MongoDB Compass is a graphical user interface (GUI) for MongoDB. It allows users to connect to databases, explore collections, view documents, create queries, and manage data without typing every command in the MongoDB Shell.
MongoDB Compass is an official graphical tool used to work with MongoDB databases. It is useful for beginners because it presents database information visually.
Using MongoDB Compass, you can:
Follow these steps to download MongoDB Compass:
Use the official website to obtain the latest compatible version for your system.
After opening MongoDB Compass, you can connect to a locally running MongoDB server.
Local connection string:
mongodb://localhost:27017
The address localhost refers to your own
computer, and 27017 is MongoDB's default
server port.
The main areas of MongoDB Compass include:
Lets you connect to a MongoDB server and manage saved connections.
Displays the databases available to your connection.
Shows collections belonging to a selected database.
Displays documents stored in a collection.
Lets you enter MongoDB query filters to find matching documents.
Provides a visual workspace for building aggregation pipelines.
Displays and helps manage indexes for a collection.
Follow these steps in MongoDB Compass:
school_db as the database name.students as the collection name.Your database and collection should now be visible in the database list.
Expected structure:
school_db
|
|-- students
You can add a document to the students
collection without using the shell.
school_db database.students collection.Example document:
{
"name": "Rahul",
"age": 20,
"course": "ADCA",
"city": "Aurangabad"
}
Compass may generate an _id field
automatically when you insert a document without one.
The Filter field lets you search for documents using MongoDB query syntax.
Example 1: Find students from Aurangabad
{
"city": "Aurangabad"
}
Example 2: Find students aged 20
{
"age": 20
}
Example 3: Find students aged over 18
{
"age": {
"$gt": 18
}
}
Enter the filter into the collection's Filter field and apply it to display matching documents.
| MongoDB Compass | MongoDB Shell |
|---|---|
| Graphical interface | Command-line interface |
| Uses buttons, tabs, and editors | Uses commands and expressions |
| Useful for visual exploration | Useful for scripting and command-based work |
| Supports visual aggregation building | Supports aggregation through commands |
| Designed for interactive database management | Useful for repeatable command workflows |
Both tools can connect to the same MongoDB server and operate on the same data.
practice_db.employees.Q1. What is MongoDB Compass?
Q2. Which connection string is commonly used for a local MongoDB server?
Q3. Which field is used to filter documents in Compass?