对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

db.serverStatus()(mongosh方法)

db.serverStatus()

返回一份概述数据库进程状态的文档。

此命令对数据库命令 serverStatus 进行封装。

此方法可用于以下环境中托管的部署:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

重要

This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.

By default, db.serverStatus() excludes in its output:

要包含默认排除的字段,请在命令中指定顶层字段并将其设置为 1。要排除默认包含的字段,请指定该字段并将其设置为 0。您可以指定顶层字段或嵌入字段。

例如,以下运算会抑制输出中的 repl、metrics 和 locks 信息。

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

以下示例在输出中包含了所有 repl 信息:

db.serverStatus( { repl: 1 } )

从MongoDB 8.3 开始,您可以通过指定 none: 1 从 db.serverStatus() 输出中排除所有可选字段。排除所有可选字段后,您可以指定要包含的字段。

此示例使用 none 最初从输出中排除所有可选字段,然后包含 locks文档。

db.serverStatus({ none: 1, locks: 1 })

The statistics reported by db.serverStatus() are reset when the mongod server is restarted. The db.serverStatus() command does not report some statistics until they have been initialized by server events.

For example, after restarting the mongod server, db.serverStatus() won't return any values for findAndModify.

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

After you run an update query, subsequent calls to db.serverStatus() display the expected metrics.

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

注意

如果在计数器开始递增之前查询特定对象,则 db.serverStatus() 方法会返回错误。

如果尚未进行任何文档更新:

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

返回:

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

默认情况下,输出中不包含 mirroredReads 信息。要返回 mirroredReads 信息,必须明确指定包含的内容:

db.serverStatus( { mirroredReads: 1 } )

要返回WiredTiger存储引擎版本,访问权限wiredTiger.version字段:

db.serverStatus().wiredTiger.version

有关此函数输出的完整文档,请参阅 serverStatus 输出。

给本页内容打分

在此页面上