@@ -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,46 +129,45 @@ 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
.. versionadded:: 3.6
135
137
136
138
* - ``filter``
137
-
138
139
- object
140
+ - .. _profile-filter-def:
139
141
140
- - Optional.
141
-
142
- A filter expression that controls which operations are
143
- profiled and logged.
142
+ Optional.
143
+ A query that determines which operations are profiled or
144
+ logged.
144
145
145
- The `` filter`` expression takes the following form:
146
+ The filter query takes the following form:
146
147
147
148
.. code-block:: javascript
148
149
149
150
{ <field1>: <expression1>, ... }
150
-
151
- The ``<field>`` can be
152
- :ref:`any field in the profiler output <profiler>`. The
153
- ``<expression>`` is a
154
- :ref:`query condition expression <query-selectors>`.
151
+
152
+ The query can be any legal :method:`~db.collection.find()`
153
+ operation where the query ``<field>`` matches a field in the
154
+ :ref:`profiler output <profiler>`.
155
155
156
156
.. note::
157
-
158
- This argument affects the same setting as the configuration
159
- option :setting:`~operationProfiling.filter`. When
160
- ``filter`` is set, the ``slowms`` and ``sampleRate``
157
+
158
+ This argument affects the same setting as the
159
+ configuration option :setting:`operationProfiling.filter`.
160
+
161
+ When ``filter`` is set, the ``slowms`` and ``sampleRate``
161
162
options are not used for profiling and slow-query log
162
163
lines.
163
164
164
165
.. versionadded:: 4.4.2
165
166
166
167
The :method:`db.getProfilingStatus()` and
167
- :method:`db.setProfilingLevel()` :doc :`shell methods
168
- </reference/method >` provide wrappers around the :dbcommand:`profile`
169
- command.
168
+ :method:`db.setProfilingLevel()` :ref :`shell methods
169
+ <js-administrative-methods >` provide wrappers around the
170
+ :dbcommand:`profile` command.
170
171
171
172
.. |binary| replace:: :binary:`~bin.mongod` or :binary:`~bin.mongos`
172
173
@@ -187,3 +188,31 @@ command against the ``admin`` database.
187
188
.. seealso::
188
189
189
190
:ref:`Database Profiling <database-profiling>`
191
+
192
+ Example
193
+ -------
194
+
195
+ Enable profiling and filter the logged data:
196
+
197
+ .. code-block:: javascript
198
+
199
+ db.runCommand(
200
+ {
201
+ profile: 1,
202
+ filter:
203
+ {
204
+ $or:
205
+ [
206
+ { millis: { $gte: 100 } },
207
+ { user: "testuser@admin" }
208
+ ]
209
+ }
210
+ }
211
+ )
212
+
213
+ The :ref:`filter <profile-filter-def>` only selects operations that
214
+ are:
215
+
216
+ - at least ``100`` milliseconds long, or
217
+ - submitted by the ``testuser``.
218
+
0 commit comments