Docs Home → Develop Applications → MongoDB Manual
db.collection.latencyStats()![](/docs/v5.3/assets/link.svg)
On this page
Definition![](/docs/v5.3/assets/link.svg)
db.collection.latencyStats(options)
Important
mongosh Method
This is a
mongosh
method. This is not the documentation forNode.js
or other programming language specific driver methods.In most cases,
mongosh
methods work the same way as the legacymongo
shell methods. However, some legacy methods are unavailable inmongosh
.For the legacy
mongo
shell documentation, refer to the documentation for the corresponding MongoDB Server release:For MongoDB API drivers, refer to the language specific MongoDB driver documentation.
db.collection.latencyStats()
returns latency statistics for a given collection. It is a wrapper around$collStats
.This method has the form:
db.collection.latencyStats( { histograms: <boolean> } ) The
histograms
argument is an optional boolean. Ifhistograms: true
thenlatencyStats()
adds latency histograms to the return document.
Tip
See also:
Output![](/docs/v5.3/assets/link.svg)
latencyStats()
returns a document containing
a field latencyStats
, containing the following fields:
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 64-bit integer giving the total combined
latency in microseconds. | |||||||||||||||
ops | A 64-bit integer 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:
|
Examples![](/docs/v5.3/assets/link.svg)
You can run latencyStats()
in
mongosh
as follows:
db.data.latencyStats( { histograms: true } ).pretty()
latencyStats()
returns a document such as
the following:
{ "ns" : "test.data", "localTime" : ISODate("2016-11-01T21:56:28.962Z"), "latencyStats" : { "reads" : { "histogram" : [ { "micros" : NumberLong(16), "count" : NumberLong(6) }, { "micros" : NumberLong(512), "count" : NumberLong(1) } ], "latency" : NumberLong(747), "ops" : NumberLong(7) }, "writes" : { "histogram" : [ { "micros" : NumberLong(64), "count" : NumberLong(1) }, { "micros" : NumberLong(24576), "count" : NumberLong(1) } ], "latency" : NumberLong(26845), "ops" : NumberLong(2) }, "commands" : { "histogram" : [ ], "latency" : NumberLong(0), "ops" : NumberLong(0) } } }