Return One Shard Key Analysis for One Cluster

GET /api/atlas/v2/groups/{groupId}/clusters/{clusterName}/shardKeyAnalyses/{analysisId}

Returns one completed shard key analysis for the specified cluster. This resource exists only once the operation that produced it has succeeded and reports no operation status of its own. MongoDB Cloud retains an analysis for 30 days.

Role requirements
  • Project Data Access Admin
  • Project Data Access Read Only
  • Project Data Access Read Write
  • Project Stream Processing Owner

Path parameters

  • groupId string Required

    Unique 24-hexadecimal digit string that identifies your project. Use the /groups endpoint to retrieve all projects to which the authenticated user has access.

    NOTE: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.

    Format should match the following pattern: ^([a-f0-9]{24})$.

  • clusterName string Required

    Human-readable label that identifies the cluster with the shard key analysis you want to return.

    Format should match the following pattern: ^[a-zA-Z0-9][a-zA-Z0-9-]*$.

  • analysisId string Required

    Unique 24-hexadecimal digit string that identifies the shard key analysis to return.

    Format should match the following pattern: ^([a-f0-9]{24})$.

Query parameters

  • envelope boolean

    Flag that indicates whether Application wraps the response in an envelope JSON object. Some API clients cannot access the HTTP response headers or status code. To remediate this, set envelope=true in the query. Endpoints that return a list of results use the results object as an envelope. Application adds the status parameter to the response body.

    Default value is false.

  • pretty boolean

    Flag that indicates whether the response body should be in the prettyprint format.

    Default value is false.

    Prettyprint

Responses

  • 200 application/vnd.atlas.2025-03-12+json

    OK

    Hide headers attributes Show headers attributes
    • RateLimit-Limit

      The maximum number of requests that a user can make within a specific time window.

    • RateLimit-Remaining

      The number of requests remaining in the current rate limit window before the limit is reached.

    Hide response attributes Show response attributes object
    • avgDocSizeBytes integer(int64)

      Average size of one document in the collection, in bytes.

      Minimum value is 0.

    • correlationCoefficient number(double)

      Correlation between the candidate shard key and the order in which documents were inserted, from -1 to 1. Values near 1 or -1 indicate a monotonically changing key, which directs all inserts to one shard. This parameter is absent when the shard key has no supporting index or the collection is clustered, in which case MongoDB Cloud does not compute it.

      Minimum value is -1, maximum value is 1.

    • createdAt string(date-time) Required

      Date and time when this shard key analysis was requested (ISO 8601 format in UTC). This is when the analysis was submitted, not when it completed; the completion time is the updatedAt of the operation that produced it.

    • expiresAt string(date-time) Required

      Date and time when MongoDB Cloud stops returning this shard key analysis (ISO 8601 format in UTC). Reads after this time return an HTTP 404 status.

    • id string Required

      Unique 24-hexadecimal digit string that identifies this shard key analysis. This is the same identifier as the operationId of the operation that produced it.

      Format should match the following pattern: ^([a-f0-9]{24})$.

    • isUnique boolean

      Flag that indicates whether the index supporting the candidate shard key enforces a uniqueness constraint.

    • monotonicity string

      Whether the shard key value increases or decreases with the order in which documents were inserted. A monotonically changing shard key directs all inserts to one shard. UNKNOWN indicates that MongoDB Cloud could not determine monotonicity, which happens when the shard key has no supporting index or the collection is clustered.

      Values are MONOTONIC, NOT_MONOTONIC, or UNKNOWN.

    • mostCommonValues array[object]

      Shard key values that occur most frequently in the sampled documents, with how often each occurs. MongoDB Cloud returns this parameter only to callers that can read the collection's data, because it carries values out of the collection rather than statistics about them.

      Not more than 100 elements.

      Hide mostCommonValues attributes Show mostCommonValues attributes object

      Shard key value that occurs frequently in the sampled documents, with the number of sampled documents that carry it.

      • frequency integer(int64)

        Number of sampled documents that carry this shard key value.

        Minimum value is 0.

      • truncated boolean

        Flag that indicates whether MongoDB Cloud omitted value because it was too large to return. When this flag is true, frequency still describes a real shard key value even though the value itself is absent.

      • value object

        Shard key value, given as one field-value pair per shard key field. This parameter is absent when truncated is true.

        Hide value attribute Show value attribute object
        • * object Additional properties

          Shard key value, given as one field-value pair per shard key field. This parameter is absent when truncated is true.

    • namespace string Required

      Combination of the database and collection that was analyzed, written as <database>.<collection>.

    • note string

      Guidance from MongoDB on how to interpret the metrics in this analysis. This parameter is absent when the analysis carries no guidance.

    • numDistinctValues integer(int64)

      Number of distinct values that the candidate shard key takes across the sampled documents. A value close to numDocsSampled indicates high cardinality, which distributes documents well.

      Minimum value is 0.

    • numDocsSampled integer(int64)

      Number of documents that MongoDB Cloud sampled to compute these metrics.

      Minimum value is 0.

    • numDocsTotal integer(int64)

      Number of documents in the collection.

      Minimum value is 0.

    • numOrphanDocs integer(int64)

      Number of orphaned documents in the collection. This parameter is absent for collections that have none.

      Minimum value is 0.

    • percentageOfMultiShardReads number(double)

      Percentage of sampled reads that the candidate shard key would route to more than one shard but not to every shard.

      Minimum value is 0, maximum value is 100.

    • percentageOfMultiShardWrites number(double)

      Percentage of sampled writes that the candidate shard key would route to more than one shard but not to every shard.

      Minimum value is 0, maximum value is 100.

    • percentageOfScatterGatherReads number(double)

      Percentage of sampled reads that the candidate shard key would broadcast to every shard. Lower is better.

      Minimum value is 0, maximum value is 100.

    • percentageOfScatterGatherWrites number(double)

      Percentage of sampled writes that the candidate shard key would broadcast to every shard. Lower is better.

      Minimum value is 0, maximum value is 100.

    • percentageOfSingleShardReads number(double)

      Percentage of sampled reads that the candidate shard key would route to exactly one shard. Higher is better.

      Minimum value is 0, maximum value is 100.

    • percentageOfSingleShardWrites number(double)

      Percentage of sampled writes that the candidate shard key would route to exactly one shard. Higher is better.

      Minimum value is 0, maximum value is 100.

    • rawOutput string

      Unmodified result of the analyzeShardKey command, as a JSON string. Its content tracks the MongoDB server version of the analyzed cluster rather than the version of this resource, so members outside the parameters above may appear or change without a new resource version. Do not parse it as a stable contract. mostCommonValues is removed from it for callers that cannot read the collection's data. This parameter is absent if MongoDB Cloud could not serialize the command result, which costs the raw view but not the analysis.

    • readSampleSize object

      Number of sampled read operations that MongoDB Cloud used to compute the read distribution, broken down by the command that issued them.

      Hide readSampleSize attributes Show readSampleSize attributes object
      • aggregate integer(int64)

        Number of sampled aggregate operations.

        Minimum value is 0.

      • count integer(int64)

        Number of sampled count operations.

        Minimum value is 0.

      • distinct integer(int64)

        Number of sampled distinct operations.

        Minimum value is 0.

      • find integer(int64)

        Number of sampled find operations.

        Minimum value is 0.

      • total integer(int64)

        Total number of sampled read operations.

        Minimum value is 0.

    • shardKey array[object]

      Candidate shard key that was analyzed, given as one object per shard key field in the order the fields form the key. This parameter is absent when MongoDB Cloud has no shard key recorded for the analysis.

      Not more than 32 elements.

      Hide shardKey attribute Show shardKey attribute object

      Key-value pair that sets one shard key field as the key and how it was indexed as its value: 1 for an ascending range-based field, hashed for a hashed field.

      • * string Additional properties

        Key-value pair that sets one shard key field as the key and how it was indexed as its value: 1 for an ascending range-based field, hashed for a hashed field.

    • writeSampleSize object

      Number of sampled write operations that MongoDB Cloud used to compute the write distribution, broken down by the command that issued them.

      Hide writeSampleSize attributes Show writeSampleSize attributes object
      • delete integer(int64)

        Number of sampled delete operations.

        Minimum value is 0.

      • findAndModify integer(int64)

        Number of sampled findAndModify operations.

        Minimum value is 0.

      • total integer(int64)

        Total number of sampled write operations.

        Minimum value is 0.

      • update integer(int64)

        Number of sampled update operations.

        Minimum value is 0.

  • 400 application/json

    Bad Request.

    Hide response attributes Show response attributes object
    • badRequestDetail object

      Bad request detail.

      Hide badRequestDetail attribute Show badRequestDetail attribute object
      • fields array[object]

        Describes all violations in a client request.

        Hide fields attributes Show fields attributes object
        • description string Required

          A description of why the request element is bad.

        • field string Required

          A path that leads to a field in the request body.

    • detail string | null

      Describes the specific conditions or reasons that cause each type of error.

    • error integer(int32) Required

      HTTP status code returned with this error.

      External documentation
    • errorCode string Required

      Application error code returned with this error.

    • parameters array[object]

      Parameters used to give more information about the error.

    • reason string | null

      Application error message returned with this error.

  • 401 application/json

    Unauthorized.

    Hide response attributes Show response attributes object
    • badRequestDetail object

      Bad request detail.

      Hide badRequestDetail attribute Show badRequestDetail attribute object
      • fields array[object]

        Describes all violations in a client request.

        Hide fields attributes Show fields attributes object
        • description string Required

          A description of why the request element is bad.

        • field string Required

          A path that leads to a field in the request body.

    • detail string | null

      Describes the specific conditions or reasons that cause each type of error.

    • error integer(int32) Required

      HTTP status code returned with this error.

      External documentation
    • errorCode string Required

      Application error code returned with this error.

    • parameters array[object]

      Parameters used to give more information about the error.

    • reason string | null

      Application error message returned with this error.

  • 403 application/json

    Forbidden.

    Hide response attributes Show response attributes object
    • badRequestDetail object

      Bad request detail.

      Hide badRequestDetail attribute Show badRequestDetail attribute object
      • fields array[object]

        Describes all violations in a client request.

        Hide fields attributes Show fields attributes object
        • description string Required

          A description of why the request element is bad.

        • field string Required

          A path that leads to a field in the request body.

    • detail string | null

      Describes the specific conditions or reasons that cause each type of error.

    • error integer(int32) Required

      HTTP status code returned with this error.

      External documentation
    • errorCode string Required

      Application error code returned with this error.

    • parameters array[object]

      Parameters used to give more information about the error.

    • reason string | null

      Application error message returned with this error.

  • 404 application/json

    Not Found.

    Hide response attributes Show response attributes object
    • badRequestDetail object

      Bad request detail.

      Hide badRequestDetail attribute Show badRequestDetail attribute object
      • fields array[object]

        Describes all violations in a client request.

        Hide fields attributes Show fields attributes object
        • description string Required

          A description of why the request element is bad.

        • field string Required

          A path that leads to a field in the request body.

    • detail string | null

      Describes the specific conditions or reasons that cause each type of error.

    • error integer(int32) Required

      HTTP status code returned with this error.

      External documentation
    • errorCode string Required

      Application error code returned with this error.

    • parameters array[object]

      Parameters used to give more information about the error.

    • reason string | null

      Application error message returned with this error.

  • 429 application/json

    Too Many Requests.

    Hide headers attributes Show headers attributes
    • RateLimit-Limit

      The maximum number of requests that a user can make within a specific time window.

    • RateLimit-Remaining

      The number of requests remaining in the current rate limit window before the limit is reached.

    • Retry-After

      The minimum time you should wait, in seconds, before retrying the API request. This header might be returned for 429 or 503 error responses.

    Hide response attributes Show response attributes object
    • badRequestDetail object

      Bad request detail.

      Hide badRequestDetail attribute Show badRequestDetail attribute object
      • fields array[object]

        Describes all violations in a client request.

        Hide fields attributes Show fields attributes object
        • description string Required

          A description of why the request element is bad.

        • field string Required

          A path that leads to a field in the request body.

    • detail string | null

      Describes the specific conditions or reasons that cause each type of error.

    • error integer(int32) Required

      HTTP status code returned with this error.

      External documentation
    • errorCode string Required

      Application error code returned with this error.

    • parameters array[object]

      Parameters used to give more information about the error.

    • reason string | null

      Application error message returned with this error.

  • 500 application/json

    Internal Server Error.

    Hide response attributes Show response attributes object
    • badRequestDetail object

      Bad request detail.

      Hide badRequestDetail attribute Show badRequestDetail attribute object
      • fields array[object]

        Describes all violations in a client request.

        Hide fields attributes Show fields attributes object
        • description string Required

          A description of why the request element is bad.

        • field string Required

          A path that leads to a field in the request body.

    • detail string | null

      Describes the specific conditions or reasons that cause each type of error.

    • error integer(int32) Required

      HTTP status code returned with this error.

      External documentation
    • errorCode string Required

      Application error code returned with this error.

    • parameters array[object]

      Parameters used to give more information about the error.

    • reason string | null

      Application error message returned with this error.

GET /api/atlas/v2/groups/{groupId}/clusters/{clusterName}/shardKeyAnalyses/{analysisId}
atlas api shardKeyAnalyzer getShardKeyAnalysis --help
import (
	"os"
	"context"
	"log"
	sdk "go.mongodb.org/atlas-sdk/v20250312001/admin"
)

func main() {
	ctx := context.Background()
	clientID := os.Getenv("MONGODB_ATLAS_CLIENT_ID")
	clientSecret := os.Getenv("MONGODB_ATLAS_CLIENT_SECRET")

	// See https://dochub.mongodb.org/core/atlas-go-sdk-oauth
	client, err := sdk.NewClient(sdk.UseOAuthAuth(clientID, clientSecret))

	if err != nil {
		log.Fatalf("Error: %v", err)
	}

	params = &sdk.GetGroupClusterShardKeyAnalysisApiParams{}
	sdkResp, httpResp, err := client.ShardKeyAnalyzerApi.
		GetGroupClusterShardKeyAnalysisWithParams(ctx, params).
		Execute()
}
curl --include --header "Authorization: Bearer ${ACCESS_TOKEN}" \
  --header "Accept: application/vnd.atlas.2025-03-12+json" \
  -X GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/shardKeyAnalyses/{analysisId}?pretty=true"
curl --user "${PUBLIC_KEY}:${PRIVATE_KEY}" \
  --digest --include \
  --header "Accept: application/vnd.atlas.2025-03-12+json" \
  -X GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/shardKeyAnalyses/{analysisId}?pretty=true"
Response examples (200)
# Headers

# Payload
{
  "avgDocSizeBytes": 42,
  "correlationCoefficient": 42.0,
  "createdAt": "2026-05-04T09:42:00Z",
  "expiresAt": "2026-05-04T09:42:00Z",
  "id": "32b6e34b3d91647abb20e7b8",
  "isUnique": true,
  "monotonicity": "MONOTONIC",
  "mostCommonValues": [
    {
      "frequency": 42,
      "truncated": true,
      "value": {
        "additionalProperty1": {},
        "additionalProperty2": {}
      }
    }
  ],
  "namespace": "string",
  "note": "string",
  "numDistinctValues": 42,
  "numDocsSampled": 42,
  "numDocsTotal": 42,
  "numOrphanDocs": 42,
  "percentageOfMultiShardReads": 42.0,
  "percentageOfMultiShardWrites": 42.0,
  "percentageOfScatterGatherReads": 42.0,
  "percentageOfScatterGatherWrites": 42.0,
  "percentageOfSingleShardReads": 42.0,
  "percentageOfSingleShardWrites": 42.0,
  "rawOutput": "string",
  "readSampleSize": {
    "aggregate": 42,
    "count": 42,
    "distinct": 42,
    "find": 42,
    "total": 42
  },
  "shardKey": [
    {
      "additionalProperty1": "string",
      "additionalProperty2": "string"
    }
  ],
  "writeSampleSize": {
    "delete": 42,
    "findAndModify": 42,
    "total": 42,
    "update": 42
  }
}
Response examples (400)
{
  "detail": "(This is just an example, the exception may not be related to this endpoint) No provider AWS exists.",
  "error": 400,
  "errorCode": "VALIDATION_ERROR",
  "reason": "Bad Request"
}
Response examples (401)
{
  "detail": "(This is just an example, the exception may not be related to this endpoint)",
  "error": 401,
  "errorCode": "NOT_ORG_GROUP_CREATOR",
  "reason": "Unauthorized"
}
Response examples (403)
{
  "detail": "(This is just an example, the exception may not be related to this endpoint)",
  "error": 403,
  "errorCode": "CANNOT_CHANGE_GROUP_NAME",
  "reason": "Forbidden"
}
Response examples (404)
{
  "detail": "(This is just an example, the exception may not be related to this endpoint) Cannot find resource AWS",
  "error": 404,
  "errorCode": "RESOURCE_NOT_FOUND",
  "reason": "Not Found"
}
Response examples (429)
{
  "detail": "(This is just an example, the exception may not be related to this endpoint)",
  "error": 429,
  "errorCode": "RATE_LIMITED",
  "reason": "Too Many Requests"
}
Response examples (500)
{
  "detail": "(This is just an example, the exception may not be related to this endpoint)",
  "error": 500,
  "errorCode": "UNEXPECTED_ERROR",
  "reason": "Internal Server Error"
}