@@ -18,36 +18,39 @@ Definition
1818 .. versionchanged:: 5.0
1919
2020 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
2222 profiler captures and records data on the performance of write
2323 operations, cursors, and database commands on a running
2424 :binary:`~bin.mongod` instance. If the profiler is disabled, the
2525 command configures how slow operations are logged to the diagnostic
2626 log.
2727
2828 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>`
3639
3740 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:
4443
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+
4548 Starting in MongoDB 4.0, for a :binary:`~bin.mongos` instance, the
4649 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.
5154
5255 .. include:: /includes/log-changes-to-database-profiler.rst
5356
@@ -75,7 +78,6 @@ Definition
7578
7679 .. _slowms-threshold-option:
7780
78-
7981 .. list-table::
8082 :header-rows: 1
8183 :widths: 20 20 80
@@ -111,7 +113,7 @@ Definition
111113
112114 .. note::
113115 This argument affects the same setting as the configuration option
114- :setting:`~ operationProfiling.slowOpThresholdMs`.
116+ :setting:`operationProfiling.slowOpThresholdMs`.
115117
116118
117119
@@ -127,46 +129,45 @@ Definition
127129 .. note::
128130
129131 This argument affects the same setting as the configuration option
130- :setting:`~ operationProfiling.slowOpSampleRate` and does not
132+ :setting:`operationProfiling.slowOpSampleRate` and does not
131133 affect the :ref:`slow oplog entry log messages on secondaries
132134 (available starting in MongoDB 4.2) <slow-oplog>`.
133135
134136 .. versionadded:: 3.6
135137
136138 * - ``filter``
137-
138139 - object
140+ - .. _profile-filter-def:
139141
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.
144145
145- The `` filter`` expression takes the following form:
146+ The filter query takes the following form:
146147
147148 .. code-block:: javascript
148149
149150 { <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>`.
155155
156156 .. 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``
161162 options are not used for profiling and slow-query log
162163 lines.
163164
164165 .. versionadded:: 4.4.2
165166
166167The :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.
170171
171172.. |binary| replace:: :binary:`~bin.mongod` or :binary:`~bin.mongos`
172173
@@ -187,3 +188,31 @@ command against the ``admin`` database.
187188.. seealso::
188189
189190 :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