Definition定义
db.collection.latencyStats(options)-
Important
mongosh
Method方法This page documents a本页记录了一种mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.mongosh方法。这不是数据库命令或特定语言驱动程序(如Node.js)的文档。For the database command, see the对于数据库命令,请参阅latencyStatsfield returned by thecollStatscommand.collStats命令返回的latencyStats字段。For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.有关MongoDB API驱动程序,请参阅特定语言的MongoDB驱动程序文档。db.collection.latencyStats()returns latency statistics for a given collection. It is a wrapper around返回给定集合的延迟统计信息。它是$collStats.$collStats的包装。This method has the form:此方法的形式如下:db.collection.latencyStats( { histograms: <boolean> } )Thehistogramsargument is an optional boolean. Ifhistograms: truethenlatencyStats()adds latency histograms to the return document.histograms(直方图)参数是一个可选的布尔值。如果histograms: true,则latencyStats()将延迟直方图添加到返回文档中。
Tip
Compatibility兼容性
This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
Note
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.所有MongoDB Atlas集群都支持此命令。有关Atlas支持所有命令的信息,请参阅不支持的命令。
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
Output输出
latencyStats() returns a document containing a field latencyStats, containing the following fields:latencyStats()返回一个包含字段latencyStatis的文档,该字段包含以下字段:
reads | |
writes | |
commands | |
transactions |
Each of these fields contains an embedded document with the following fields:每个字段都包含一个嵌入式文档,其中包含以下字段:
latency | |||||||
ops | |||||||
histogram |
|
| [1] |
|
Examples示例
You can run 您可以在latencyStats() in mongosh as follows:mongosh中运行latencyStats(),如下所示:
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" : Long(16),
"count" : Long(6)
},
{
"micros" : Long(512),
"count" : Long(1)
}
],
"latency" : Long(747),
"ops" : Long(7)
},
"writes" : {
"histogram" : [
{
"micros" : Long(64),
"count" : Long(1)
},
{
"micros" : Long(24576),
"count" : Long(1)
}
],
"latency" : Long(26845),
"ops" : Long(2)
},
"commands" : {
"histogram" : [ ],
"latency" : Long(0),
"ops" : Long(0)
}
}
}