Configure the Slow Query Threshold
- OAuth 2.0 authentication for programmatic access to Cloud Manager is available as a Preview feature.
- The feature and the corresponding documentation might change at any time during the Preview period. To use OAuth 2.0 authentication, create a service account to use in your requests to the Cloud Manager Public API.
The Performance Advisor recognizes a query as slow if it takes longer
to execute than the value of
slowms.
By default, this value is 100
milliseconds. You can change the
threshold with either the
profile
command or the db.setProfilingLevel()
mongosh
method.
Example
The following profile
command example sets the threshold at 200
milliseconds:
db.runCommand({ profile: 0, slowms: 200 })
If you are running MongoDB 4.2 or later, you can customize the
percentage of slow queries in your logs used by the Performance Advisor
by specifying the sampleRate
parameter.
Example
This sets the slow query threshold to a lower value of 100 milliseconds but also sets the sample rate to 10%.
db.runCommand({ profile: 0, slowms: 100, sampleRate: 0.1 })
Note
By default, the value of profile
is 0
. MongoDB recommends
leaving this value unchanged since other values can negatively
impact database performance. To learn more, see the
profile command.