@@ -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,44 +129,43 @@ 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 * - ``filter``
135-
136137 - object
138+ - .. _profile-filter-def:
137139
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.
142143
143- The `` filter`` expression takes the following form:
144+ The filter query takes the following form:
144145
145146 .. code-block:: javascript
146147
147148 { <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>`.
153153
154154 .. 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``
159160 options are not used for profiling and slow-query log
160161 lines.
161162
162163 .. versionadded:: 4.4.2
163164
164165The :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.
168169
169170.. |binary| replace:: :binary:`~bin.mongod` or :binary:`~bin.mongos`
170171
@@ -185,3 +186,31 @@ command against the ``admin`` database.
185186.. seealso::
186187
187188 :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