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

top(数据库命令)

top

top是一条管理命令,用于返回每个集合的使用情况统计信息。您可以使用top 指标来比较各集合的相对性能。

重要

top命令必须针对mongod实例运行。对mongos实例运行top 会返回错误。

对于每个集合,top 会返回每个事件执行所需的time count量(以微秒为单位)以及每个事件已执行的次数。time 和count 指标仅在您重新启动mongod 实例后重置。

使用 Queryable Encryption 时,top 命令仅返回集合名称。

此命令可用于以下环境中托管的部署:

  • MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务

top对管理员数据库发出 命令:

db.runCommand(
{
top: 1
}
)

top命令返回以下事件字段的使用统计信息:

字段
说明

total

所有 readLock 和 writeLock 操作的组合。

readLock

使用读锁的操作的使用统计。这些操作包括但不限于查询和聚合。

writeLock

使用写锁的操作的使用情况统计信息。这些操作包括但不限于插入、更新和删除文档。

queries

查询操作(如 find)的使用统计。queries.time 和 queries.count 字段也会更新 readLock.time 并递增 readLock.count。

getmore

getMore 操作的使用统计。

insert

insert 操作的使用统计。insert.time 和 insert.count 字段也会更新 writeLock.time 并递增 writeLock.count。

update

update 操作的使用统计。update.time 和 update.count 字段也会更新 writeLock.time 并递增 writeLock.count。

remove

delete 操作的使用统计。remove.time 和 remove.count 字段也会更新 writeLock.time 并递增 writeLock.count。

commands

聚合、创建索引和删除索引等操作的使用情况统计信息。根据命令类型,commands.time 和 commands.count 字段会更新 writeLock 字段或 readLock 字段。

例如,聚合操作会递增 readLock.time 和 readLock.count。索引创建时,会递增 writeLock.time 和 writeLock.count。

top命令的输出类似于以下输出:

{
"totals" : {
note: "all times in microseconds",
"records.users" : {
"total" : {
"time" : 305277,
"count" : 2825
},
"readLock" : {
"time" : 305264,
"count" : 2824
},
"writeLock" : {
"time" : 13,
"count" : 1
},
"queries" : {
"time" : 305264,
"count" : 2824
},
"getmore" : {
"time" : 0,
"count" : 0
},
"insert" : {
"time" : 0,
"count" : 0
},
"update" : {
"time" : 0,
"count" : 0
},
"remove" : {
"time" : 0,
"count" : 0
},
"commands" : {
"time" : 0,
"count" : 0
}
}
}