For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Shard Key Analyzer

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.

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.

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.

To use Shard Key Advisor, your cluster must meet the following requirements:

  • MongoDB Version: MongoDB 8.0 or later.

  • Cluster Tier: M10 cluster 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.

To use Shard Key Advisor:

1
  1. If it's not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.

  2. If it's not already displayed, select your desired project from the Projects menu in the navigation bar.

  3. In the sidebar, click Clusters under the Database heading.

The Clusters page displays.

2

Open Performance Advisor for your cluster.

  1. Click the ... button for the cluster you want to analyze.

  2. Click View Performance Advisor.

The Performance Advisor page displays.

3

Click the Sharding Recommendations tab in the Performance Advisor navigation.

Sharding recommendations appear when Atlas identifies collections that may benefit from sharding or resharding.

4

Click a recommendation card to view its details.

The recommendation details page displays metrics and analysis for the suggested shard key.

5

The Shard Key Advisor opens in a new browser tab.

6

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.

7

To view read and write distribution metrics:

  1. Click Enable Query Sampling in the analyzer.

  2. Click Enable Sampling.

  3. Wait for Atlas to collect query data. The time needed depends on your cluster's query volume.

  4. 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.

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.

To learn more about shard keys and sharding concepts, see: