Navigation

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 the db.runCommand( { <command> } ) method.

The profile command has the following syntax:

{ profile: <level> }

The following profiling levels are available:

Level Description
-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 }

Changed in version 3.6: The command can also take the following options:

Option Type Description
txnNumber 64-bit integer/long

Optional.

A strictly increasing non-negative number that uniquely identifies the command in the command’s session.

If specified, the command must also include the lsid option.

New in version 3.6.

lsid Document

Optional.

The document that specifies the unique id of the session associated with the command. If the txnNumber is specified, the lsid is required.

Tip

The mongo shell and the drivers provide helpers to start the session and set the lsid for the commands.

New in version 3.6.

mongod writes the output of the database profiler to the system.profile collection.

mongod records queries that take longer than the slowOpThresholdMs 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 the mongo 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.

←   ping serverStatus  →