You can view the slow query logs of a database in an instance 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.
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 provided free of charge.
Usage notes
The retention period of slow query logs is seven days.
Slow query logs cannot be deleted.
You cannot view the slow query logs of databases in a standalone instance.
The log management feature is unavailable in some regions. You can log on to the ApsaraDB for MongoDB console to check whether the feature is supported in a specified region.
Procedure
Go to the Replica Set Instances or Sharded Cluster Instances page. In the top navigation bar, select the region in which the instance resides. Then, find the instance and click the ID of the instance.
In the left-side navigation pane of the instance details page, choose .
Perform operations to view slow query logs based on the instance architecture.
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.