
How to Use MongoDB Compass to Explore and Manage Your Data
The shell is great when you know exactly what you're looking for. It's less great when you've inherited a database and have no idea what's in it, when you need to see whether a field is sometimes a string and sometimes a number, or when you're building a seven-stage aggregation pipeline and want to see the output of each stage as you go.
MongoDB Compass is MongoDB's official desktop GUI. It connects to any MongoDB deployment (local, self-hosted, or Atlas) and gives you a visual way to browse documents, run queries, analyze a collection's schema, build aggregations stage by stage, manage indexes, read explain plans, and import or export data. It's free, runs on Windows, macOS, and Linux, and includes an embedded mongosh for the moments when typing is faster.
This guide covers installing Compass and connecting, browsing and editing documents, writing queries in the filter bar, schema analysis, the aggregation pipeline builder, index and explain plan tools, schema validation, import and export, and a few habits that keep you from accidentally damaging production data.
Installing Compass
Download Compass from the MongoDB website, or use a package manager:
# macOS
brew install --cask mongodb-compass
# Windows
winget install MongoDB.Compass.Full
# Debian/Ubuntu (download the .deb from the Compass download page first)
sudo apt install ./mongodb-compass_*_amd64.deb
Compass updates itself on Windows and macOS. Keep it current, since new releases regularly add features and support for new server capabilities.
Connecting to a Deployment
When Compass opens, you'll see the connection screen. The fastest way to connect is to paste a connection string:
mongodb://localhost:27017
or, for Atlas:
mongodb+srv://app_dev:<password>@dev-cluster.ab1cd.mongodb.net/
In Atlas, click Connect on your cluster and choose Compass to get a string pre-filled with your cluster address. (If you don't have a cluster yet, see Getting Started with MongoDB Atlas.)
Advanced Connection Options
Click Advanced Connection Options to configure things a URI alone can't easily express:
- Authentication: username/password, X.509 certificates, LDAP, Kerberos, OIDC, or AWS IAM.
- TLS/SSL: CA files and client certificates for self-hosted clusters with TLS enabled.
- Proxy/SSH: connect through an SSH tunnel to a database that isn't reachable directly, which is common for servers inside a private network.
- Advanced: read preference, replica set name, default database, and other URI options.
Compass converts everything back into a connection string, so you can switch between the form and the raw URI.
Saving Connections
Click the star to save a connection as a favorite, give it a name, and pick a color. Use the color on purpose: many teams reserve red for production, so the environment is obvious at a glance. Recent Compass versions can hold several connections open at once in the sidebar, which makes comparing data between staging and production easier, and makes the color coding even more important.
Browsing Databases and Collections
Once connected, the left sidebar lists databases and collections. Click a collection to open it in a tab. At the top of each collection tab you'll find the main work areas:
- Documents: browse, query, insert, edit, and delete documents.
- Aggregations: build and run aggregation pipelines.
- Schema: analyze the shape and types of the data.
- Indexes: view, create, and drop indexes.
- Validation: view and edit schema validation rules.
The Documents view has three display modes: List (expandable documents), JSON (raw Extended JSON), and Table (a spreadsheet-style grid, where you can drill into nested fields). Table view is excellent for scanning many documents with a consistent shape. JSON view is best for copying documents into code or tests.
Creating Databases and Collections
Click the + next to a database or the "Create database" button. Compass asks for a database name and a first collection name, since MongoDB doesn't persist an empty database. The collection dialog also lets you create special collection types, like time series, capped, or clustered collections, and set a collation.
Querying with the Filter Bar
The filter bar at the top of the Documents tab accepts a standard MongoDB filter document, exactly as you'd write it in mongosh:
{ status: "shipped", total: { $gte: 100 } }
Click Options to expand the full query form:
| Field | What it does | Example |
|---|---|---|
| Project | Limit returned fields | { orderNo: 1, total: 1, _id: 0 } |
| Sort | Order results | { createdAt: -1 } |
| Collation | Language-aware comparison rules | { locale: "en", strength: 2 } |
| Hint | Force a specific index | { status: 1, createdAt: -1 } |
| Skip | Skip a number of documents | 20 |
| Limit | Cap the number of results | 10 |
| Max Time MS | Abort if the query runs too long | 5000 |
Compass autocompletes field names based on a sample of the collection's documents, which helps a lot with unfamiliar data. It also keeps a query history (the clock icon), and you can save frequently used queries as favorites.
A few filter examples that are worth keeping around:
// Documents created in the last 7 days (use your own date)
{ createdAt: { $gte: ISODate("2026-09-20T00:00:00Z") } }
// Documents where a field is missing
{ phone: { $exists: false } }
// Documents where a field is stored as the wrong type
{ total: { $type: "string" } }
// Match one element of an array of sub-documents
{ items: { $elemMatch: { sku: "SKU-1042", qty: { $gt: 1 } } } }
If query operators are still new to you, A Complete Guide to MongoDB Query Operators covers every one of these.
Natural Language Queries
Compass has optional generative AI features that turn a plain-English prompt ("orders over 100 dollars shipped to Germany last month") into a filter or aggregation. They must be enabled in settings and require signing in with an Atlas account, and some organizations disable them by policy. Treat the output like code from a colleague: read it before you run it, especially against production.
Inserting, Editing, and Deleting Documents
Insert: click Add Data > Insert Document. You can type a single document or paste an array of documents in JSON mode. Compass understands Extended JSON, so you can write { "$date": "2026-09-27T00:00:00Z" } to insert a real date.
Edit: hover over a document and click the pencil icon. In list view, you can change values, change a field's type from a dropdown (for example, from String to Int32 or Date), add fields, or remove them. Changes aren't saved until you click Update.
Clone: the copy icon creates a new document pre-filled with the current one's fields, minus _id. It's handy for creating test data.
Delete: the trash icon marks a document for deletion; confirm to remove it.
Bulk Update and Delete
Recent versions of Compass can apply an update or delete to every document matching the current filter. Enter a filter, then use the Update or Delete buttons above the results. For updates, you write an update document:
{
$set: { status: "archived" },
$currentDate: { archivedAt: true }
}
Compass shows a preview of how the documents will change and how many are affected before you confirm. Read that count carefully. A bulk operation with an empty filter touches the entire collection.
Analyzing Schemas
The Schema tab is the feature that makes Compass indispensable for unfamiliar data. Click Analyze Schema, and Compass samples documents from the collection (by default, a random sample of up to 1,000 documents) and summarizes every field:
- Which types each field has and in what proportion. A
pricefield that's 97% Double and 3% String is a bug waiting to happen. - How often a field is missing (shown as "undefined").
- Value distributions: histograms for numbers and dates, most frequent values for strings.
- Nested fields and arrays, including array lengths.
- Geospatial data, plotted on a map if the field holds coordinates.
The charts are interactive. Click a bar in a histogram, or a value in a list, and Compass builds a query for it in the filter bar. Shift-click to select multiple values. This is a quick way to go from "some orders have a weird status" to a filter that finds exactly those orders.
You can also export the analyzed schema as JSON, including a generated JSON Schema, which is a good starting point for writing validation rules.
Because analysis is based on a sample, rare variations may not show up. If you're hunting a needle, combine the Schema tab with a targeted $type query.
Building Aggregation Pipelines
The Aggregations tab provides a visual pipeline builder. Each stage is a card where you choose an operator (like $match, $group, or $lookup) from a dropdown, and Compass fills in a template for its syntax. As you edit, each stage shows a live preview of sample documents coming out of it, so you can see exactly what each step does.
Here's a pipeline you might build stage by stage to find top customers by revenue:
[
{
$match: {
status: "delivered",
createdAt: { $gte: ISODate("2026-01-01T00:00:00Z") },
},
},
{
$group: {
_id: "$customerId",
revenue: { $sum: "$total" },
orders: { $sum: 1 },
},
},
{ $sort: { revenue: -1 } },
{ $limit: 10 },
{
$lookup: {
from: "customers",
localField: "_id",
foreignField: "_id",
as: "customer",
},
},
{ $unwind: "$customer" },
{ $project: { _id: 0, name: "$customer.name", revenue: 1, orders: 1 } },
];
Useful features in the builder:
- Toggle stages on and off to see how the output changes without deleting anything.
- Text mode switches the whole pipeline to editable text, so you can paste in an existing pipeline from code.
- Stage wizard offers guided forms for common tasks like grouping or joining, if you don't want to write syntax by hand.
- Save a pipeline to reuse later, or create a view from it.
- Export to language turns the pipeline into ready-to-paste code for Node.js, Python, Java, C#, Go, and other drivers.
Export to language is also available for queries in the Documents tab, and it's one of the quickest ways to get correctly formatted driver code when you're switching between languages.
Preview output is computed on a sample of documents. When you click Run, the full pipeline runs against the whole collection, so for large collections, make sure your $match is selective and indexed first.
Managing Indexes
The Indexes tab lists every index on the collection with its keys, type, size, and usage statistics (how many times it's been used since the server last restarted). An index with zero usage over a long uptime is a candidate for removal, since every index slows down writes and uses memory.
Click Create Index to add one. You pick fields and directions, and set options like:
- Unique, to enforce no duplicates.
- Partial filter expression, to index only documents matching a filter.
- TTL, to expire documents automatically after a number of seconds.
- Wildcard projections, for indexing unpredictable field names.
- Collation, for language-aware string comparison.
For Atlas clusters, Compass also shows Atlas Search indexes in the same area.
Dropping an index is a click away, which is exactly why you should be careful. Before dropping an index in production, check that it's truly unused, and consider hiding it first (db.collection.hideIndex() in mongosh) so you can unhide it instantly if performance drops.
Reading Explain Plans
From the Documents or Aggregations tab, click Explain to see how MongoDB executes your query. Compass shows the plan as a visual tree, with a summary at the top:
- Documents returned vs. documents examined vs. index keys examined.
- Whether the query used an index, and which one.
- Whether the sort was done in memory (a common source of slowness).
- Execution time.
The healthiest queries examine roughly as many documents as they return. If Compass shows 250,000 documents examined for 12 returned, and a COLLSCAN stage, you need an index. Toggle to the raw JSON view for the full explain output when you need details.
Schema Validation
The Validation tab shows the collection's validation rules and lets you edit them. You can write a $jsonSchema validator and choose the validation action (error rejects invalid writes, warn only logs them) and validation level (strict checks all writes, moderate skips existing invalid documents).
{
"$jsonSchema": {
"bsonType": "object",
"required": ["email", "createdAt"],
"properties": {
"email": { "bsonType": "string", "pattern": "^.+@.+$" },
"createdAt": { "bsonType": "date" }
}
}
}
Compass shows sample documents that pass and fail the rules before you apply them, which is a great way to check the impact of a new validator on existing data. Starting in warn mode is a sensible way to roll out validation on a live collection.
Importing and Exporting Data
From a collection's Add Data menu, choose Import JSON or CSV file. For CSV imports, Compass lets you pick the type of each column (String, Number, Date, Boolean, and so on) before importing, which avoids the classic problem of every number arriving as a string. You can also choose to stop on errors or skip bad rows.
To export, click Export Data and choose between exporting the full collection or only the results of the current query, then choose JSON or CSV and which fields to include. JSON exports use Extended JSON, so types survive a round trip.
For very large datasets or scripted, repeatable jobs, the command-line tools are a better fit. See Importing and Exporting Data with mongoimport and mongoexport.
The Embedded mongosh
Click Open MongoDB shell (the >_ button) to open a full mongosh session connected to the same deployment, docked at the bottom of the window. Everything works: helpers, JavaScript, show collections, and admin commands. It's perfect for the things the GUI doesn't cover, like running db.currentOp() or creating users.
db.orders.aggregate([{ $group: { _id: "$status", n: { $sum: 1 } } }]);
Best Practices for Using Compass Safely
Color-code your connections. Make production red and give it a clear name. Most accidental production changes happen because someone thought they were in staging.
Use a read-only database user for production browsing. If your job is to investigate data, connect with a user that has the read role. Compass then simply can't modify anything. Compass also has a read-only mode setting that hides write controls.
Be careful with Schema analysis and full pipelines on huge collections. Sampling is designed to be light, but running an unindexed aggregation with Run on a production collection with hundreds of millions of documents can hurt performance for real users. Point heavy exploration at a secondary or an analytics node when possible (set the read preference in Advanced Connection Options).
Double-check bulk operation counts. Before confirming a bulk update or delete, compare the affected count with what you expected.
Don't leave connection strings with passwords lying around. Compass stores saved connections, including credentials, locally. On shared machines, don't save passwords, and prefer authentication methods like OIDC where your organization supports them.
Conclusion
Compass turns MongoDB from a black box into something you can see. Connect with a connection string, browse documents in list, JSON, or table view, and query with the same filter syntax you'd use in code. Use the Schema tab to find inconsistent types and missing fields, the Aggregations builder to develop pipelines one stage at a time with live previews, the Indexes and Explain tools to understand performance, and the Validation tab to enforce the rules you discover. When you need the command line, the embedded mongosh is one click away.
As a next step, connect Compass to a database you work with regularly, open the busiest collection, and click Analyze Schema. Look for any field with more than one type. That five-minute check finds real bugs more often than you'd expect.


