Requires M10+ clusters running MongoDB 8.0 or later in commercial Atlas deployments
Atlas Shard Key Advisor helps you analyze and evaluate candidate shard keys for your collections. Access the analyzer through Performance Advisor to evaluate shard keys based on your cluster's query patterns and workload characteristics. The analyzer provides immediate analysis with optional query sampling for deeper insights into read and write distribution.
Atlas provides recommendations in Performance Advisor to help you identify when sharding decisions may improve your cluster's performance:
When to shard a replica set.
When to move a collection.
When to shard an unsharded collection.
When to add more shards.
Use Shard Key Advisor to analyze candidate shard keys for these recommendations.
You can also open Shard Key Advisor from the Sharding Insights page. In the Recommendations card, click Analyze Shard Keys.
About This Feature
Choosing the right shard key is critical for sharded cluster performance. A well-chosen shard key:
Distributes data evenly across shards.
Routes queries efficiently to minimize cross-shard operations.
Supports your application's query patterns.
Scales as your data grows.
Shard Key Advisor analyzes your collection's query patterns and provides analysis based on:
Query routing efficiency.
Data distribution characteristics.
Key cardinality and frequency.
Read and write patterns.
How It Works
Shard Key Advisor provides immediate analysis and optional deeper insights:
Immediate Analysis
The analyzer computes key characteristics without requiring query sampling:
Cardinality: Measures the uniqueness of values in candidate fields.
Monotonicity: Identifies whether field values increase or decrease over time.
Frequency: Analyzes the distribution of values across the field.
These metrics help you understand how well a candidate shard key distributes data and avoids hotspots.
Optional Query Sampling
For deeper insights into query patterns, enable query sampling to view:
Read Distribution: Shows which shard key values your queries access most frequently.
Write Distribution: Shows which shard key values your writes target most frequently.
Query sampling is optional. The analyzer prompts you to enable it when viewing distribution metrics. When enabled, Atlas samples queries run against your collection and re-analyzes the candidate shard keys with the additional data.
Prerequisites
To use Shard Key Advisor, your cluster must meet the following requirements:
MongoDB Version: MongoDB 8.0 or later.
Cluster Tier:
M10cluster tier or higher.Environment: Commercial Atlas deployments only. Shard Key Advisor is not available for:
Atlas Data Regionalization customers.
Cloud Manager deployments.
Ops Manager deployments.
Government cloud environments.
Collection Type: Shard Key Advisor does not support time series collections.
Get Started
To use Shard Key Advisor:
In Atlas, go to the Clusters page for your project.
If it's not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.
If it's not already displayed, select your desired project from the Projects menu in the navigation bar.
In the sidebar, click Clusters under the Database heading.
The Clusters page displays.
Open Performance Advisor for your cluster.
Click the ... button for the cluster you want to analyze.
Click View Performance Advisor.
The Performance Advisor page displays.
Review the analysis.
The analyzer provides immediate analysis of candidate shard keys, including:
Cardinality: Uniqueness of values in the field.
Monotonicity: Whether values increase or decrease over time.
Frequency: Distribution of values across the field.
These metrics are available immediately without query sampling.
(Optional) Enable query sampling for deeper analysis.
To view read and write distribution metrics:
Click Enable Query Sampling in the analyzer.
Click Enable Sampling.
Wait for Atlas to collect query data. The time needed depends on your cluster's query volume.
Click Re-analyze to view updated metrics with read/write distribution data.
When query sampling is disabled, the analyzer prompts you to enable it for distribution metrics.
Performance and Storage Considerations
Sampled queries are stored on your cluster with a 7-day TTL. Query sampling does not stop automatically, so you must disable it manually when you no longer need it.
Atlas sets the sampling rate to 5 samples per second. To learn more about how sampling rates and query sizes affect storage, see the configureQueryAnalyzer documentation.
Note
The sampling rate is set by Atlas and cannot be adjusted through Shard Key Advisor.
The analyzeShardKey command processes each analysis phase sequentially, so it might take some time to complete on large collections. It does not block reads or writes on your cluster.
Tip
To cancel a long-running analyzeShardKey operation, use the Kill Op button in the Real-Time Performance Panel. You must have the Project Real Time Performance Operator role.
Learn More
To learn more about shard keys and sharding concepts, see: