Skip to main content

MongoDB Compass

MongoDB Compass is the desktop GUI for MongoDB. Use it when you want to connect to a database, inspect collections, run filters, edit documents, create indexes, and export/import data without using terminal commands.

Connect To MongoDB

Open MongoDB Compass and paste your connection string.

Local MongoDB:

mongodb://127.0.0.1:27017

MongoDB Atlas:

mongodb+srv://username:password@cluster.mongodb.net/

Then click Connect.

Create A Database

  1. Click Create database.
  2. Enter a database name.
  3. Enter the first collection name.
  4. Click Create Database.

Example:

Database: dspgrid
Collection: users

Browse Data

  1. Select a database from the left sidebar.
  2. Select a collection.
  3. Open the Documents tab.

This is where you can view, filter, add, edit, and delete documents.

Insert A Document

  1. Open a collection.
  2. Click Add Data.
  3. Choose Insert Document.
  4. Add JSON.
  5. Click Insert.

Example:

{
"name": "Ali",
"email": "ali@example.com",
"role": "admin",
"active": true
}

Filter Documents

Use the filter bar in the Documents tab.

Find by email:

{ "email": "ali@example.com" }

Find active users:

{ "active": true }

Find by role:

{ "role": "admin" }

Find names containing text:

{ "name": { "$regex": "ali", "$options": "i" } }

Query ObjectId Values

In Compass filters, ObjectId values must use ObjectId("..."). Do not search _id as a plain string unless your database stored it as a string.

Find by _id:

{ "_id": ObjectId("665f2f2b8a5a8d4f0c9d1234") }

Find by referenced user ID:

{ "userId": ObjectId("665f2f2b8a5a8d4f0c9d1234") }

Find multiple ObjectIds:

{
"_id": {
"$in": [
ObjectId("665f2f2b8a5a8d4f0c9d1234"),
ObjectId("665f2f2b8a5a8d4f0c9d5678")
]
}
}

Find documents not matching an ObjectId:

{ "userId": { "$ne": ObjectId("665f2f2b8a5a8d4f0c9d1234") } }

If your field was saved as a string, query it as a string:

{ "userId": "665f2f2b8a5a8d4f0c9d1234" }

Query Dates And Times

MongoDB stores dates as UTC. In Compass filters, use ISODate("...") for date fields.

Find documents after a date:

{ "createdAt": { "$gte": ISODate("2026-05-01T00:00:00.000Z") } }

Find documents before a date:

{ "createdAt": { "$lt": ISODate("2026-06-01T00:00:00.000Z") } }

Find documents between two dates:

{
"createdAt": {
"$gte": ISODate("2026-05-01T00:00:00.000Z"),
"$lt": ISODate("2026-06-01T00:00:00.000Z")
}
}

Find documents for one full UTC day:

{
"createdAt": {
"$gte": ISODate("2026-05-25T00:00:00.000Z"),
"$lt": ISODate("2026-05-26T00:00:00.000Z")
}
}

Find documents at or after a specific time:

{ "createdAt": { "$gte": ISODate("2026-05-25T15:30:00.000Z") } }

Find documents updated in a date range:

{
"updatedAt": {
"$gte": ISODate("2026-05-20T00:00:00.000Z"),
"$lte": ISODate("2026-05-25T23:59:59.999Z")
}
}

Sort newest first after applying a date filter:

{ "createdAt": -1 }

Use this in the Sort box, not the Filter box.

Query Missing Or Empty Fields

Find documents where a field exists:

{ "email": { "$exists": true } }

Find documents where a field is missing:

{ "email": { "$exists": false } }

Find null values:

{ "deletedAt": null }

Find empty strings:

{ "email": "" }

Project Fields

Use Project to control which fields appear.

Show only name and email:

{ "name": 1, "email": 1, "_id": 0 }

Hide a field:

{ "password": 0 }

Sort Documents

Use Sort in the query bar.

Newest first:

{ "createdAt": -1 }

Name A to Z:

{ "name": 1 }

Limit Results

Use Limit to restrict result count.

Example:

10

Edit A Document

  1. Open the Documents tab.
  2. Find the document.
  3. Click the edit icon.
  4. Change the field value.
  5. Click Update.

Use this carefully on production databases.

Delete A Document

  1. Find the document.
  2. Click the trash/delete icon.
  3. Confirm deletion.

Delete only after checking the database and collection name.

Create An Index

  1. Open a collection.
  2. Go to the Indexes tab.
  3. Click Create Index.
  4. Add the field and sort direction.
  5. Choose options such as unique if needed.
  6. Click Create Index.

Email unique index:

{ "email": 1 }

Use Unique when every value must be different.

Aggregations

  1. Open a collection.
  2. Go to the Aggregations tab.
  3. Add stages.
  4. Preview the output.

Group users by role:

{
"$group": {
"_id": "$role",
"count": { "$sum": 1 }
}
}

Filter active users first:

{
"$match": {
"active": true
}
}

Import Data

  1. Open a collection.
  2. Click Add Data.
  3. Choose Import JSON or CSV file.
  4. Select the file.
  5. Review import settings.
  6. Click Import.

Export Data

  1. Open a collection.
  2. Apply a filter if needed.
  3. Click Export Data.
  4. Choose JSON or CSV.
  5. Export selected fields or full documents.

Duplicate A Connection

Use saved connections when switching between local, staging, and production databases.

Recommended naming:

Local - DSPGrid
Staging - DSPGrid
Production - DSPGrid

Safety Checklist

  • Confirm whether you are connected to local, staging, or production.
  • Avoid deleting documents directly in production.
  • Use filters before editing bulk data.
  • Create indexes during low-traffic windows for large collections.
  • Export a backup before risky manual edits.
  • Do not share connection strings with passwords.

Common Compass Use Cases

  • Check if API data is being saved correctly.
  • Inspect user records.
  • Find documents by ID or email.
  • Test MongoDB filters visually.
  • Create indexes without terminal commands.
  • Export a small dataset for debugging.
  • Import seed data during development.