MongoDBUsing Compass — Deep Dive

MongoDB Compass

MongoDB Compass is the official GUI for MongoDB. It lets you explore your data, run queries, view performance metrics, build aggregation pipelines, and manage indexes — all without writing shell commands.

Installing Compass

Bash
# macOS — install with Homebrew Cask
brew install --cask mongodb-compass

# Or download the installer directly:
# https://www.mongodb.com/try/download/compass
  1. Go to mongodb.com/try/download/compass

  2. Select your OS (Windows .exe, macOS .dmg, Linux .deb / .rpm)

  3. Run the downloaded installer and follow the prompts

  4. Launch MongoDB Compass from your Applications folder or Start Menu

Connecting to a Database
  1. Open MongoDB Compass

  2. Click "New Connection"

  3. Paste a connection string or fill in the host/port/auth form

  4. Click "Save & Connect"

Note
For a local MongoDB installation, use the connection string: mongodb://localhost:27017
Navigating the Interface

Panel

Purpose

Databases view

Lists all databases with their storage sizes

Collections view

Lists collections within the selected database

Documents tab

Browse, filter, insert, edit, and delete documents

Schema tab

Visualizes field types and value distributions from a sample

Aggregations tab

Build and test aggregation pipelines visually

Indexes tab

View, create, and drop indexes; shows index size and usage

Explain Plan tab

Shows the query execution plan (IXSCAN vs COLLSCAN)

Performance tab

Real-time server metrics: operations/sec, memory, network

Viewing and Filtering Documents

Filter bar syntax (same as MongoDB query)

JSON
{ "age": { "$gt": 25 }, "status": "active" }

The filter bar at the top of the Documents tab accepts any valid MongoDB query document. You can also add a Projection to show only specific fields, and a Sort to order results. All three fields use standard MongoDB JSON syntax.

The Schema Tab

Compass analyzes a sample of documents and visualizes the schema — field types, value distributions, minimum/maximum/average for numbers, and date ranges. Clicking on a chart segment automatically populates the filter bar with the corresponding query.

Note
Schema analysis is based on a sample of 1 000 documents by default. Results for very large or heterogeneous collections may not be fully representative.
Building Aggregation Pipelines
  1. Click the Aggregations tab for a collection

  2. Click "Add Stage" and select a stage operator (e.g. $match)

  3. Fill in the stage JSON in the editor panel

  4. Add more stages as needed — the output preview updates live

  5. Click "Export to Language" to generate Node.js, Python, Java, or C# driver code

Managing Indexes

The Indexes tab shows every index on the collection along with its size and usage statistics. You can create new indexes by clicking "Create Index" and entering the key specification, or drop unused indexes to free storage and improve write performance.

Creating an index in Compass

JSON
{ "email": 1 }

After entering the key, check Unique to enforce uniqueness, or Sparse to exclude documents that lack the indexed field.

Explain Plan

The Explain Plan tab shows exactly how MongoDB executes a query. Look for IXSCAN (index scan — fast) versus COLLSCAN (collection scan — reads every document). The winning plan section shows which index was chosen and how many keys were examined versus how many documents were returned. A high keys-examined-to-returned ratio signals a poor index.

Tip
Use the Aggregations tab's "Export to Language" feature to automatically generate driver code for Node.js, Python, Java, or C# from any pipeline you build visually.
Warning
Compass performs schema analysis on a sample of 1 000 documents by default. Large collections may not be fully represented, so treat the schema visualization as an approximation rather than a guarantee.