This document outlines a number of key administration options for the database profiler. For additional related infor- mation, consider the following resources: 

• Database Profiler Output (page 292) 

• Profile Command 

• db.currentOp() 

## Profiling Levels 

The following profiling levels are available: 

• 0 - the profiler is off, does not collect any data. mongod always writes operations longer than the slowOpThresholdMs threshold to its log. 

• 1 - collects profiling data for slow operations only. By default slow operations are those slower than 100 milliseconds. 

You can modify the threshold for “slow” operations with the slowOpThresholdMs runtime option or the setParameter command. See the Specify the Threshold for Slow Operations (page 228) section for more information. 

• 2 - collects profiling data for all database operations. 

## Enable Database Profiling and Set the Profiling Level 

You can enable database profiling from the mongo shell or through a driver using the profile command. This section will describe how to do so from the mongo shell. See your driver documentation if you want to control the profiler from within your application. 

When you enable profiling, you also set the profiling level (page 228). The profiler records data in the system.profile (page 291) collection. MongoDB creates the system.profile (page 291) collection in a database after you enable profiling for that database. 

To enable profiling and set the profiling level, use the db.setProfilingLevel() helper in the mongo shell, passing the profiling level as a parameter. For example, to enable profiling for all database operations, consider the following operation in the mongo shell: 

db.setProfilingLevel(2) 

The shell returns a document showing the previous level of profiling. The "ok" : 1 key-value pair indicates the operation succeeded: 

{ "was" : 0, "slowms" : 100, "ok" : 1 } 

To verify the new setting, see the Check Profiling Level (page 229) section. 

Specify the Threshold for Slow Operations The threshold for slow operations applies to the entire mongod in- stance. When you change the threshold, you change it for all databases on the instance. 

Important: Changing the slow operation threshold for the database profiler also affects the profiling subsystem’s slow operation threshold for the entire mongod instance. Always set the threshold to the highest useful value. 

By default the slow operation threshold is 100 milliseconds. Databases with a profiling level of 1 will log operations slower than 100 milliseconds. 

