Database Manual / Reference / mongosh Methods / Databases

db.serverStatus() (mongosh method方法)

db.serverStatus()

Returns a document that provides an overview of the database process's state.返回一个文档,提供数据库进程状态的概述。

This command provides a wrapper around the database command serverStatus.此命令为数据库命令serverStatus提供了一个包装器。

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部署的完全托管服务

Important

This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.M0和Flex集群不支持此命令。有关详细信息,请参阅不支持的命令

  • 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的源代码可用、免费使用和自我管理版本

Behavior行为

By default, db.serverStatus() excludes in its output:默认情况下,db.serverStatus()在其输出中排除:

To include fields that are excluded by default, specify the top-level field and set it to 1 in the command. To exclude fields that are included by default, specify the field and set to 0. You can specify either top-level or embedded fields.要包含默认情况下排除的字段,请指定顶级字段并在命令中将其设置为1。要排除默认包含的字段,请指定该字段并将其设置为0。您可以指定顶级字段或嵌入字段。

For example, the following operation suppresses the repl, metrics and locks information in the output.例如,以下操作会抑制输出中的replmetricslocks信息。

db.serverStatus( { repl: 0,  metrics: 0, locks: 0 } )

The following example includes all repl information in the output:以下示例包括输出中的所有repl信息:

db.serverStatus( { repl: 1 } )

Initialization初始化

The statistics reported by db.serverStatus() are reset when the mongod server is restarted. mongod服务器重新启动时,db.serverStatus()报告的统计信息将被重置。The db.serverStatus() command does not report some statistics until they have been initialized by server events.db.serverStatus()命令在服务器事件初始化之前不会报告某些统计信息。

For example, after restarting the mongod server, db.serverStatus() won't return any values for findAndModify.例如,重新启动mongod服务器后,db.serverStatus()不会为findAndModify返回任何值。

db.serverStatus().metrics.commands.findAndModify
// No results returned

After you run an update query, subsequent calls to db.serverStatus() display the expected metrics.运行更新查询后,对db.serverStatus()的后续调用将显示预期的指标。

{
"arrayFilters" : Long(0),
"failed" : Long(0),
"pipeline" : Long(0),
"total" : Long(1)
}

Note

The db.serverStatus() method returns an error if a specific object is queried before the counters have begun to increment.如果在计数器开始递增之前查询了特定对象,则db.serverStatus()方法返回错误。

If there haven't been any document updates yet:如果还没有任何文档更新:

db.serverStatus().metrics.commands.update.pipeline

Returns:返回:

TypeError: db.serverStatus(...).metrics.commands.update is undefined :
@(shell):1:1

Include 包含mirroredReads

By default, the mirroredReads information is not included in the output. 默认情况下,输出中不包括mirroredReads信息。To return mirroredReads information, you must explicitly specify the inclusion:要返回mirroredReads信息,您必须明确指定包含:

db.serverStatus( { mirroredReads: 1 } )

Output输出

See serverStatus Output for complete documentation of the output of this function.有关此函数输出的完整文档,请参阅serverStatus输出