- Reference >
- Database Commands >
- Diagnostic Commands >
- profile
profile¶
-
profile
¶ Use the
profile
command to enable, disable, or change the query profiling level. This allows administrators to capture data regarding performance. The database profiling system can impact performance and can allow the server to write the contents of queries to the log. Your deployment should carefully consider the security implications of this. The profiler is off by default.To run
profile
, use thedb.runCommand( { <command> } )
method.The
profile
command has the following syntax:{ profile: <level> }
The following profiling levels are available:
Level Setting -1 No change. Returns the current profile level. 0 Off. No profiling. The default profiler level. 1 On. Only includes slow operations. 2 On. Includes all operations. You may optionally set a threshold in milliseconds for profiling using the
slowms
option, as follows:{ profile: 1, slowms: 200 }
mongod
writes the output of the database profiler to thesystem.profile
collection.mongod
records queries that take longer than theslowOpThresholdMs
to the server log even when the database profiler is not active.See also
Additional documentation regarding Database Profiling.
See also
“
db.getProfilingStatus()
” and “db.setProfilingLevel()
” provide wrappers around this functionality in themongo
shell.Note
This command obtains a write lock on the affected database and blocks other operations until it has completed. However, the write lock is only held while enabling or disabling the profiler. This is typically a short operation.