@@ -18,36 +18,39 @@ Definition
18
18
.. versionchanged:: 5.0
19
19
20
20
For a :binary:`~bin.mongod` instance, the command enables, disables,
21
- or configures the :doc:`/tutorial/manage-the- database-profiler`. The
21
+ or configures the :ref:` database profiler <database -profiler> `. The
22
22
profiler captures and records data on the performance of write
23
23
operations, cursors, and database commands on a running
24
24
:binary:`~bin.mongod` instance. If the profiler is disabled, the
25
25
command configures how slow operations are logged to the diagnostic
26
26
log.
27
27
28
28
On :binary:`~bin.mongod`, if the :ref:`database profiler level
29
- <set-profiling-level-level>` is ``1`` or ``2`` (i.e. the
30
- :doc:`database profiler </tutorial/manage-the-database-profiler/>` is
31
- enabled), the :ref:`slowms <set-profiling-level-options-slowms>`,
32
- :ref:`sampleRate <set-profiling-level-options-sampleRate>`, and
33
- :ref:`filter <set-profiling-level-options-filter>` affect the
34
- behavior of both the profiler and the :option:`diagnostic log <mongod
35
- --logpath>`.
29
+ <set-profiling-level-level>` is ``2``, full logging is enabled on
30
+ the profiler and the :option:`diagnostic log <mongod --logpath>`.
31
+
32
+ At :ref:`database profiler level <set-profiling-level-level>` ``1``,
33
+ the following settings modify both the profiler and the
34
+ :option:`diagnostic log <mongod --logpath>`:
35
+
36
+ - :ref:`slowms <set-profiling-level-options-slowms>`
37
+ - :ref:`sampleRate <set-profiling-level-options-sampleRate>`
38
+ - :ref:`filter <set-profiling-level-options-filter>`
36
39
37
40
If the :ref:`database profiler level <set-profiling-level-level>` is
38
- ``0`` (i.e. :doc:`database profiler
39
- </tutorial/manage-the-database-profiler/>` is disabled), the
40
- :ref:`slowms <set-profiling-level-options-slowms>`,
41
- :ref:`sampleRate <set-profiling-level-options-sampleRate>`, and
42
- :ref:`filter <set-profiling-level-options-filter>` affect
43
- only the diagnostic log.
41
+ ``0``, the :ref:`database profiler <database-profiler>` is disabled.
42
+ At level ``0`` the following settings only modify the diagnostic log:
44
43
44
+ - :ref:`slowms <set-profiling-level-options-slowms>`
45
+ - :ref:`sampleRate <set-profiling-level-options-sampleRate>`
46
+ - :ref:`filter <set-profiling-level-options-filter>`
47
+
45
48
Starting in MongoDB 4.0, for a :binary:`~bin.mongos` instance, the
46
49
command only configures how operations get written to the diagnostic
47
- log. You cannot enable the
48
- :doc:`/tutorial/manage-the- database-profiler` on a
49
- :binary:`~bin.mongos` instance because `` mongos`` does not have any
50
- collections that the profiler can write to.
50
+ log. You cannot enable the :ref:`database profiler
51
+ < database-profiler> ` on a :binary:`~bin.mongos` instance because
52
+ `` mongos`` does not have any collections that the profiler can write
53
+ to.
51
54
52
55
.. include:: /includes/log-changes-to-database-profiler.rst
53
56
@@ -75,7 +78,6 @@ Definition
75
78
76
79
.. _slowms-threshold-option:
77
80
78
-
79
81
.. list-table::
80
82
:header-rows: 1
81
83
:widths: 20 20 80
@@ -111,7 +113,7 @@ Definition
111
113
112
114
.. note::
113
115
This argument affects the same setting as the configuration option
114
- :setting:`~ operationProfiling.slowOpThresholdMs`.
116
+ :setting:`operationProfiling.slowOpThresholdMs`.
115
117
116
118
117
119
@@ -127,44 +129,43 @@ Definition
127
129
.. note::
128
130
129
131
This argument affects the same setting as the configuration option
130
- :setting:`~ operationProfiling.slowOpSampleRate` and does not
132
+ :setting:`operationProfiling.slowOpSampleRate` and does not
131
133
affect the :ref:`slow oplog entry log messages on secondaries
132
134
(available starting in MongoDB 4.2) <slow-oplog>`.
133
135
134
136
* - ``filter``
135
-
136
137
- object
138
+ - .. _profile-filter-def:
137
139
138
- - Optional.
139
-
140
- A filter expression that controls which operations are
141
- profiled and logged.
140
+ Optional.
141
+ A query that determines which operations are profiled or
142
+ logged.
142
143
143
- The `` filter`` expression takes the following form:
144
+ The filter query takes the following form:
144
145
145
146
.. code-block:: javascript
146
147
147
148
{ <field1>: <expression1>, ... }
148
-
149
- The ``<field>`` can be
150
- :ref:`any field in the profiler output <profiler>`. The
151
- ``<expression>`` is a
152
- :ref:`query condition expression <query-selectors>`.
149
+
150
+ The query can be any legal :method:`~db.collection.find()`
151
+ operation where the query ``<field>`` matches a field in the
152
+ :ref:`profiler output <profiler>`.
153
153
154
154
.. note::
155
-
156
- This argument affects the same setting as the configuration
157
- option :setting:`~operationProfiling.filter`. When
158
- ``filter`` is set, the ``slowms`` and ``sampleRate``
155
+
156
+ This argument affects the same setting as the
157
+ configuration option :setting:`operationProfiling.filter`.
158
+
159
+ When ``filter`` is set, the ``slowms`` and ``sampleRate``
159
160
options are not used for profiling and slow-query log
160
161
lines.
161
162
162
163
.. versionadded:: 4.4.2
163
164
164
165
The :method:`db.getProfilingStatus()` and
165
- :method:`db.setProfilingLevel()` :doc :`shell methods
166
- </reference/method >` provide wrappers around the :dbcommand:`profile`
167
- command.
166
+ :method:`db.setProfilingLevel()` :ref :`shell methods
167
+ <js-administrative-methods >` provide wrappers around the
168
+ :dbcommand:`profile` command.
168
169
169
170
.. |binary| replace:: :binary:`~bin.mongod` or :binary:`~bin.mongos`
170
171
@@ -185,3 +186,31 @@ command against the ``admin`` database.
185
186
.. seealso::
186
187
187
188
:ref:`Database Profiling <database-profiling>`
189
+
190
+ Example
191
+ -------
192
+
193
+ Enable profiling and filter the logged data:
194
+
195
+ .. code-block:: javascript
196
+
197
+ db.runCommand(
198
+ {
199
+ profile: 1,
200
+ filter:
201
+ {
202
+ $or:
203
+ [
204
+ { millis: { $gte: 100 } },
205
+ { user: "testuser@admin" }
206
+ ]
207
+ }
208
+ }
209
+ )
210
+
211
+ The :ref:`filter <profile-filter-def>` only selects operations that
212
+ are:
213
+
214
+ - at least ``100`` milliseconds long, or
215
+ - submitted by the ``testuser``.
216
+
0 commit comments