Return All Suggested Indexes

GET /api/atlas/v2/groups/{groupId}/clusters/{clusterName}/performanceAdvisor/suggestedIndexes

Returns the indexes that the Performance Advisor suggests. The Performance Advisor monitors queries that MongoDB considers slow and suggests new indexes to improve query performance. To use this resource, the requesting Service Account or API Key must have the Project Read Only role.

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.

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

Query parameters

  • processIds array[string]

    ProcessIds from which to retrieve suggested indexes. A processId is a combination of host and port that serves the MongoDB process. The host must be the hostname, FQDN, IPv4 address, or IPv6 address of the host that runs the MongoDB process (mongod or mongos). The port must be the IANA port on which the MongoDB process listens for requests. To include multiple processIds, pass the parameter multiple times delimited with an ampersand (&) between each processId.

    Format of each should match the following pattern: ^([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-f]{1,4}\:){7}([0-9a-f]{1,4})|(([a-z0-9]+\.){1,10}[a-z]+)?(\:[0-9]{4,5})$.

  • namespaces array[string]

    Namespaces from which to retrieve suggested indexes. A namespace consists of one database and one collection resource written as .: <database>.<collection>. To include multiple namespaces, pass the parameter multiple times delimited with an ampersand (&) between each namespace. Omit this parameter to return results for all namespaces.

  • since integer(int64)

    Date and time from which the query retrieves the suggested indexes. This parameter expresses its value in the number of milliseconds that have elapsed since the UNIX epoch.

    • If you don't specify the until parameter, the endpoint returns data covering from the since value and the current time.
    • If you specify neither the since nor the until parameters, the endpoint returns data from the previous 24 hours.

    Minimum value is 1199145600000.

  • until integer(int64)

    Date and time up until which the query retrieves the suggested indexes. This parameter expresses its value in the number of milliseconds that have elapsed since the UNIX epoch.

    • If you specify the until parameter, you must specify the since parameter.
    • If you specify neither the since nor the until parameters, the endpoint returns data from the previous 24 hours.

    Minimum value is 1199145600000.

Responses

  • 200 application/vnd.atlas.2024-08-05+json

    OK

    Hide response attributes Show response attributes object
    • shapes array[object]

      List of query predicates, sorts, and projections that the Performance Advisor suggests.

      Hide shapes attributes Show shapes attributes object
      • avgMs integer(int64)

        Average duration in milliseconds for the queries examined that match this shape.

      • count integer(int64)

        Number of queries examined that match this shape.

      • id string

        Unique 24-hexadecimal digit string that identifies this shape. This string exists only for the duration of this API request.

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

      • inefficiencyScore integer(int64)

        Average number of documents read for every document that the query returns.

        Understanding the Query Inefficiency Score
      • namespace string

        Human-readable label that identifies the namespace on the specified host. The resource expresses this parameter value as <database>.<collection>.

      • operations array[object]

        List that contains specific about individual queries.

        Hide operations attributes Show operations attributes object
        • predicates array[object]

          List that contains the search criteria that the query uses. To use the values in key-value pairs in these predicates requires Project Data Access Read Only permissions or greater. Otherwise, MongoDB Cloud redacts these values.

          List that contains the search criteria that the query uses. To use the values in key-value pairs in these predicates requires Project Data Access Read Only permissions or greater. Otherwise, MongoDB Cloud redacts these values.

          List that contains the search criteria that the query uses. To use the values in key-value pairs in these predicates requires Project Data Access Read Only permissions or greater. Otherwise, MongoDB Cloud redacts these values.

        • stats object

          Details that this resource returned about the specified query.

          Hide stats attributes Show stats attributes object
          • ms integer(int64)

            Length of time expressed during which the query finds suggested indexes among the managed namespaces in the cluster. This parameter expresses its value in milliseconds. This parameter relates to the duration query parameter.

          • nReturned integer(int64)

            Number of results that the query returns.

          • nScanned integer(int64)

            Number of documents that the query read.

          • ts integer(int64)

            Date and time from which the query retrieves the suggested indexes. This parameter expresses its value in the number of seconds that have elapsed since the UNIX epoch. This parameter relates to the since query parameter.

            UNIX Epoch
    • suggestedIndexes array[object]

      List that contains the documents with information about the indexes that the Performance Advisor suggests.

      Hide suggestedIndexes attributes Show suggestedIndexes attributes object
      • avgObjSize number(double)

        The average size of an object in the collection of this index.

      • id string

        Unique 24-hexadecimal digit string that identifies this index.

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

      • impact array[string]

        List that contains unique 24-hexadecimal character string that identifies the query shapes in this response that the Performance Advisor suggests.

      • index array[object]

        List that contains documents that specify a key in the index and its sort order.

        One index key paired with its sort order. A value of 1 indicates an ascending sort order. A value of -1 indicates a descending sort order. Keys in indexes with multiple keys appear in the same order that they appear in the index.

        Hide index attribute Show index attribute object
        • * integer(int32) Additional properties

          One index key paired with its sort order. A value of 1 indicates an ascending sort order. A value of -1 indicates a descending sort order. Keys in indexes with multiple keys appear in the same order that they appear in the index.

          Values are 1 or -1.

      • namespace string

        Human-readable label that identifies the namespace on the specified host. The resource expresses this parameter value as <database>.<collection>.

      • weight number(double)

        Estimated performance improvement that the suggested index provides. This value corresponds to Impact in the Performance Advisor user interface.

  • 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

      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

      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

      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

      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

      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

      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

      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

      Application error message returned with this error.

  • 429 application/json

    Too Many Requests.

    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

      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

      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

      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

      Application error message returned with this error.

GET /api/atlas/v2/groups/{groupId}/clusters/{clusterName}/performanceAdvisor/suggestedIndexes
atlas api listClusterSuggestedIndexes --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")

	client, err := sdk.NewClient(
		sdk.UseOAuthAuth(clientID, clientSecret),
		sdk.UseBaseURL(url))

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

	params = &sdk.ListClusterSuggestedIndexesApiParams{}
	sdkResp, httpResp, err := client.PerformanceAdvisorApi.
		ListClusterSuggestedIndexesWithParams(ctx, params).
		Execute()
}
curl --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}/performanceAdvisor/suggestedIndexes?pretty=true"
curl --user "${PUBLIC_KEY}:${PRIVATE_KEY}" \
  --digest \
  --header "Accept: application/vnd.atlas.2025-03-12+json" \
  -X GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/performanceAdvisor/suggestedIndexes?pretty=true"
Response examples (200)
{
  "shapes": [
    {
      "avgMs": 42,
      "count": 42,
      "id": "32b6e34b3d91647abb20e7b8",
      "inefficiencyScore": 42,
      "namespace": "string",
      "operations": [
        {
          "predicates": [
            {}
          ],
          "stats": {
            "ms": 42,
            "nReturned": 42,
            "nScanned": 42,
            "ts": 42
          }
        }
      ]
    }
  ],
  "suggestedIndexes": [
    {
      "avgObjSize": 42.0,
      "id": "32b6e34b3d91647abb20e7b8",
      "impact": [
        "string"
      ],
      "index": [
        {
          "additionalProperty1": 1,
          "additionalProperty2": 1
        }
      ],
      "namespace": "string",
      "weight": 42.0
    }
  ]
}
Response examples (400)
{
  "error": 400,
  "detail": "(This is just an example, the exception may not be related to this endpoint) No provider AWS exists.",
  "reason": "Bad Request",
  "errorCode": "VALIDATION_ERROR"
}
Response examples (401)
{
  "error": 401,
  "detail": "(This is just an example, the exception may not be related to this endpoint)",
  "reason": "Unauthorized",
  "errorCode": "NOT_ORG_GROUP_CREATOR"
}
Response examples (403)
{
  "error": 403,
  "detail": "(This is just an example, the exception may not be related to this endpoint)",
  "reason": "Forbidden",
  "errorCode": "CANNOT_CHANGE_GROUP_NAME"
}
Response examples (404)
{
  "error": 404,
  "detail": "(This is just an example, the exception may not be related to this endpoint) Cannot find resource AWS",
  "reason": "Not Found",
  "errorCode": "RESOURCE_NOT_FOUND"
}
Response examples (429)
{
  "error": 429,
  "detail": "(This is just an example, the exception may not be related to this endpoint)",
  "reason": "Too Many Requests",
  "errorCode": "RATE_LIMITED"
}
Response examples (500)
{
  "error": 500,
  "detail": "(This is just an example, the exception may not be related to this endpoint)",
  "reason": "Internal Server Error",
  "errorCode": "UNEXPECTED_ERROR"
}