You can view the slow query logs of a database in the ApsaraDB for MongoDB console and analyze the logs to optimize the database.
Prerequisites
The instance is a replica set instance or a sharded cluster instance.
ImportantYou can find standalone instances in the replica set instance list, but you cannot view slow query logs of standalone instances.
If the instance was purchased between June 6, 2021 and November 25, 2021, the audit log feature is enabled and slow is selected in the Audit Log Filter Setting panel. For more information about how to enable the audit log feature, see Enable the audit log feature.
NoteIf only slow is selected in the Audit Log Filter Setting panel, the audit log feature is offered free of charge.
Usage notes
The retention period of slow query logs is seven days.
Slow query logs cannot be deleted.
Procedure
Log on to the ApsaraDB for MongoDB console.
In the left-side navigation pane, click Replica Set Instances or Sharded Cluster Instances.
In the upper-left corner of the page that appears, select the resource group and region to which the desired instance belongs.
Click the ID of the instance that you want to manage or click Manage in the Actions column.
In the left-side navigation pane of the instance details page, choose .
Perform operations to view slow query logs based on the instance type.
Replica set instances
Specify the database name and time range to view slow query logs.
Sharded cluster instances
Specify the database name, shard node ID, and time range to view slow query logs.
NoteClick Export to download the slow query logs to your on-premises computer.
References
For more information about how to view detailed slow query logs or export slow query logs, see Slow query logs.