On this page


db.setProfilingLevel(level, options)

Configures the database profiler. This method provides a wrapper around the profile command.

Parameter Type Description
level integer

Configures the profiler level. The following profiler levels are available:

Level Description
0 The profiler is off and does not collect any data. This is the default profiler level.
1 The profiler collects data for operations that take longer than the value of slowms.
2 The profiler collects data for all operations.
options document or integer

Optional. Accepts an integer or an options document. If an integer value is passed as the options argument instead of a document, the value is assigned to slowms. The following options are available:

Default: 100
Type: integer

The slow operation time threshold, in milliseconds. Operations that run for longer than this threshold are considered slow.

The system log and profiler are configured separately but share the same settings for slowms and sampleRate. When logLevel is set to 0, mongod records slow queries to the system log at a rate determined by slowOpSampleRate. At higher logLevel settings, all queries appear in the system log regardless of their latency.


This argument affects the same setting as the configuration file option slowOpThresholdMs.

Default: 1.0
Type: double

The fraction of slow operations that should be profiled. sampleRate accepts values between 0 and 1, inclusive.


This argument affects the same setting as the configuration option slowOpSampleRate.


Profiling can impact performance and shares settings with the system log. Carefully consider any performance and security implications before configuring and enabling the profiler on a production deployment.

See Profiler Overhead for more information on potential performance degradation.