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
- Click Create database.
- Enter a database name.
- Enter the first collection name.
- Click Create Database.
Example:
Database: dspgrid
Collection: users
Browse Data
- Select a database from the left sidebar.
- Select a collection.
- Open the Documents tab.
This is where you can view, filter, add, edit, and delete documents.
Insert A Document
- Open a collection.
- Click Add Data.
- Choose Insert Document.
- Add JSON.
- 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
- Open the Documents tab.
- Find the document.
- Click the edit icon.
- Change the field value.
- Click Update.
Use this carefully on production databases.
Delete A Document
- Find the document.
- Click the trash/delete icon.
- Confirm deletion.
Delete only after checking the database and collection name.
Create An Index
- Open a collection.
- Go to the Indexes tab.
- Click Create Index.
- Add the field and sort direction.
- Choose options such as unique if needed.
- Click Create Index.
Email unique index:
{ "email": 1 }
Use Unique when every value must be different.
Aggregations
- Open a collection.
- Go to the Aggregations tab.
- Add stages.
- Preview the output.
Group users by role:
{
"$group": {
"_id": "$role",
"count": { "$sum": 1 }
}
}
Filter active users first:
{
"$match": {
"active": true
}
}
Import Data
- Open a collection.
- Click Add Data.
- Choose Import JSON or CSV file.
- Select the file.
- Review import settings.
- Click Import.
Export Data
- Open a collection.
- Apply a filter if needed.
- Click Export Data.
- Choose JSON or CSV.
- 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.