Query Performance
Analyze and optimize MongoDB query performance
Query Performance
Analyze and optimize MongoDB query performance with MongoDash's performance analysis tools.
Query Execution Stats
BusinessView detailed execution statistics for any query:
- Execution time - Total time in milliseconds
- Documents examined - Number of documents scanned
- Documents returned - Number of results
- Index used - Which index (if any) was used
- Stage details - Performance per pipeline stage
Explain Plan
View MongoDB's explain output:
- Run a query
- Click Explain button
- Review execution plan:
- Query planner analysis
- Winning plan selection
- Rejected plan alternatives
- Index usage details
Understanding Explain Output
COLLSCAN - Full collection scan (slow on large collections) IXSCAN - Index scan (fast) FETCH - Document retrieval after index lookup SORT - In-memory sort (expensive without index)
COLLSCAN on large collections indicates missing indexes. Add appropriate indexes for better performance.
Performance Metrics
Efficiency Ratio
Documents examined vs documents returned:
- Good - Ratio close to 1 (examining only needed documents)
- Poor - High ratio (scanning many unnecessary documents)
Execution Time
Benchmark query speed:
- < 10ms - Excellent
- 10-100ms - Good
- 100-1000ms - Acceptable for complex queries
- > 1000ms - Needs optimization
Index Recommendations
MongoDash suggests indexes based on query patterns:
Single Field Index
For simple equality queries:
{ "status": 1 }
Compound Index
For queries with multiple conditions:
{ "status": 1, "createdAt": -1 }
Text Index
For full-text search:
{ "description": "text", "title": "text" }
Create indexes in order of equality, sort, range (ESR rule) for optimal performance.
Optimization Strategies
1. Add Indexes
Create indexes on frequently queried fields:
- Equality filters
- Sort fields
- Range queries
2. Use Projections
Limit returned fields to reduce data transfer:
{
"find": { "status": "active" },
"projection": { "name": 1, "email": 1 }
}
3. Limit Results
Add limits to queries that don't need all documents:
{
"find": { "status": "active" },
"limit": 100
}
4. Filter Early in Pipelines
Put $match stages early in aggregation pipelines to reduce documents processed by later stages.
Query Monitoring
EnterpriseMonitor query performance across your workspace:
- Slow query log (queries > 100ms)
- Query frequency analysis
- Index usage statistics
- Performance trends over time
Performance Testing
Test query performance before deploying:
- Run query on production-sized dataset
- Review execution stats
- Test with and without indexes
- Verify performance meets requirements