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

getAuditConfig(数据库命令)

getAuditConfig

版本 5.0 中的新增功能。

getAuditConfig is an administrative command that retrieves audit configurations from mongod and mongos server instances.

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

重要

MongoDB Atlas 集群不支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令

该命令具有以下语法:

db.adminCommand(
{
getAuditConfig: 1
}
)

Auditing must be enabled to use getAuditConfig.

未参与运行时审核配置的节点将返回其auditLog.filtersetParameter.auditAuthorizationSuccess的当前配置文件设置。

Nodes that are participating in the runtime audit synthesize their current configuration from memory. Configuration updates are distributed via the oplog mechanism which means updates on mongod nodes are distributed to secondary nodes very quickly. However, the distribution mechanism is different on mongos nodes. mongos nodes have to poll the primary server at regular intervals for configuration updates. You may see stale data due to polling delay if you run setAuditConfig on the primary server and getAuditConfig on a shard before the shard has polled the primary server for updated configuration details.

注意

如果您正在编写自动审核脚本,请注意,mongosh 和旧版 mongo shell之间用于表示集群签名的引号样式和类型有所不同。 在mongosh中,类型为 Binary 和 Long。 传统 shell 中的对应类型是 BinData 和 NumberLong。

// mongosh
signature: {
hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
keyId: Long("0")
}
// mongo
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : Long(0)
}

Run getAuditConfig on the admin database .

db.adminCommand({getAuditConfig: 1})

示例服务器配置为审核读取和写入操作。 它有一个过滤器,用于捕获所需的操作,并且auditAuthorizationSuccess值已设置为true

{
generation: ObjectId("60e73e74680a655705f16525"),
filter: {
atype: 'authCheck',
'param.command': {
'$in': [ 'find', 'insert', 'delete', 'update', 'findandmodify' ]
}
},
auditAuthorizationSuccess: true,
ok: 1,
'$clusterTime': {
clusterTime: Timestamp(1, 1625767540),
signature: {
hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
keyId: Long("0")
}
},
operationTime: Timestamp(1, 1625767540)
}
给本页内容打分