@@ -28,7 +28,8 @@ Definition
28
28
{
29
29
latencyStats: { histograms: <boolean> },
30
30
storageStats: { scale: <number> },
31
- count: {}
31
+ count: {},
32
+ queryExecStats: {}
32
33
}
33
34
}
34
35
@@ -90,6 +91,12 @@ Definition
90
91
91
92
.. versionadded:: 3.6
92
93
94
+ * - ``queryExecStats``
95
+ - Adds :ref:`query execution statistics
96
+ <collstat-queryexecstats>` to the return document.
97
+
98
+ .. versionadded:: 4.4
99
+
93
100
For a collection in a replica set or a
94
101
:ref:`non-sharded collection<sharded-vs-non-sharded-collections>` in
95
102
a cluster, ``$collStats`` outputs a single document. For a
@@ -127,16 +134,16 @@ Definition
127
134
milliseconds since the :term:`Unix epoch`.
128
135
129
136
* - ``latencyStats``
130
- - A collection of statistics related to request latency for a
131
- collection or :doc:`view </core/views>`. See
132
- :ref:`latency-stats-document` for details on this document.
137
+ - Statistics related to request latency for a collection or
138
+ :doc:`view </core/views>`. See :ref:`latency-stats-document`
139
+ for details on this document.
133
140
134
141
Only present when the ``latencyStats: {}`` option is specified.
135
142
136
143
* - ``storageStats``
137
144
138
- - A collection of statistics related to a collection's storage
139
- engine. See :ref:`storage-stats-document` for details on this
145
+ - Statistics related to a collection's storage engine. See
146
+ :ref:`storage-stats-document` for details on this
140
147
document.
141
148
142
149
The various size data is scaled by the specified factor (with
@@ -160,6 +167,13 @@ Definition
160
167
Only present when the ``count: {}`` option is specified. Returns
161
168
an error if applied to a :doc:`view </core/views>`.
162
169
170
+ * - ``queryExecStats``
171
+ - Statistics related to query execution for the collection.
172
+
173
+ Only present when the ``queryExecStats: {}`` option is
174
+ specified. Returns an error if applied to a :doc:`view
175
+ </core/views>`.
176
+
163
177
Behavior
164
178
--------
165
179
@@ -339,6 +353,40 @@ The total number of documents in the collection is also available as
339
353
``storageStats.count`` when ``storageStats: {}`` is specified. For more
340
354
information, see :ref:`storage-stats-document`.
341
355
356
+ .. _collstat-queryexecstats:
357
+
358
+ ``queryExecStats`` Document
359
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
360
+
361
+ .. versionadded:: 4.4
362
+
363
+ The ``queryExecStats`` embedded document only exists in the output if
364
+ you specify the ``queryExecStats`` option.
365
+
366
+ .. include:: /includes/fact-queryexecstats-reference.rst
367
+
368
+ For example, if you run ``$collStats`` with the ``queryExecStats: {}``
369
+ option on a ``matrices`` collection:
370
+
371
+ .. code-block:: javascript
372
+
373
+ db.matrices.aggregate( [ { $collStats: { queryExecStats: { } } } ] )
374
+
375
+ The query returns a result similar to the following:
376
+
377
+ .. code-block:: javascript
378
+
379
+ {
380
+ "ns": "test.matrices",
381
+ "host": "mongo.example.net:27017",
382
+ "localTime": ISODate("2020-06-03T14:23:29.711Z"),
383
+ "queryExecStats": {
384
+ "collectionScans": {
385
+ "total": NumberLong(33),
386
+ "nonTailable": NumberLong(31)
387
+ }
388
+ }
389
+ }
342
390
343
391
``$collStats`` on Sharded Collections
344
392
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments