- Reference >
mongo
Shell Methods >- Database Methods >
- db.setProfilingLevel()
db.setProfilingLevel()¶
On this page
Definition¶
-
db.
setProfilingLevel
(level, options)¶ The method configures database profiler level, the slowms, and the sampleRate.
If the database profiler level is
1
or2
(i.e. the database profiler is enabled), the slowms and the sampleRate affect the behavior of both the profiler and thediagnostic log
.If the database profiler level is
0
(i.e. database profiler is disabled), the slowms and the sampleRate affect only the diagnostic log.Although profiling is unavailable on
mongos
instance, starting in MongoDB 4.0, you can rundb.setProfilingLevel()
onmongos
to set the slowms and sampleRate for the diagnostic log. That is, for amongos
instance, you must specify0
for level.db.setProfilingLevel()
provides a wrapper around theprofile
command.
Syntax¶
The db.setProfilingLevel()
method has the following form:
Parameters¶
Parameter | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
level | integer | Configures the database profiler level. The following profiler levels are available:
Since profiling is not available on |
||||||||
options | document or integer | Optional. Accepts an integer or an options document. If an integer value is
passed as the
|
Returns¶
The method returns a document that contains the previous values of the settings.
- Standalone
- Replica Set Member
- mongos Instance
Where:
was
is the previous level setting.slowms
is the previous slowms setting.sampleRate
is the previous sampleRate setting.
To view the current profiling level, see db.getProfilingStatus()
.
Behavior¶
Important
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.
Examples¶
Enable Profiler and Set Slow Operation Threshhold and Sample Rate¶
The following example sets for a mongod
instance:
- the profiling level to
1
, - the slow operation threshold slowms to
20
milliseconds, and - the sampleRate to
0.42
.
The method returns a document with the previous values for the settings.
To view the current profiling level, see db.getProfilingStatus()
.
Disable Profiler and Set Slow Operation Threshhold and Sample Rate¶
The following example sets for a mongod
or
mongos
instance:
- the profiling level to
0
, - the slow operation threshold slowms to
20
milliseconds, and - the sampleRate to
0.42
.
The method returns a document with the previous values for the settings.
To view the current profiling level, see db.getProfilingStatus()
.