- Reference >
- Operators >
- Aggregation Pipeline Operators >
- Pipeline Aggregation Stages >
- $collStats (aggregation)
$collStats (aggregation)¶
On this page
Definition¶
-
$collStats¶ New in version 3.4.
Returns statistics regarding a collection or view.
The
$collStatsstage has the following prototype form:All of the fields in the argument document are optional.
latencyStatsadds latency statistics to the return document.latencyStats.histogramsadds latency histogram information tolatencyStatsiftrue.storageStatsadds storage statistics to the return document.
The return document includes the following fields:
Field Name Description nsThe namespace of the requested collection or view. localTimeThe current time on the MongoDB server, expressed as UTC milliseconds since the Unix epoch. latencyStatsA collection of statistics related to request latency for a collection or view. See latencyStats Document for details on this document.
Only exists given the
latencyStats: {}option.storageStatsA collection of statistics related to a collection’s storage engine. See storageStats Document for details on this document.
Only exists given the
storageStats: {}option. Returns an error if applied to a view.
Behavior¶
$collStats must be the first stage in an aggregation pipeline, or
else the pipeline returns an error.
latencyStats Document¶
The latencyStats embedded document only exists in the output if
$collStats receives the latencyStats option.
| Field Name | Description |
|---|---|
reads |
Latency statistics for read requests. |
writes |
Latency statistics for write requests. |
commands |
Latency statistics for database commands. |
Each of these fields contains an embedded document bearing the following fields:
| Field Name | Description | ||||||
|---|---|---|---|---|---|---|---|
latency |
A long giving the total combined
latency in microseconds. |
||||||
ops |
A long giving the total number of
operations performed on the collection since startup. |
||||||
histogram |
An array of embedded documents, each representing a latency range. Each document covers twice the previous document’s range. For upper values between 2048 microseconds and roughly 1 second, the histogram includes half-steps. This field only exists given the
Each document bears the following fields:
For example, if This indicates that there were:
|
For example, if you run $collStats with the latencyStats: {} option
on a matrices collection:
This query will return a result similar to the following:
storageStats Document¶
The storageStats embedded document only exists in the output if
$collStats receives the storageStats option.
The contents of this document are dependent on the storage engine in use. See Output for a reference on this document.
For example, if you run $collStats with the storageStats: {}
option on a matrices collection using the WiredTiger Storage Engine:
This query will return a result similar to the following:
Performing $collStats with the storageStats option on a
view results in an error.
See also