切换 $queryStats 日志输出
MongoDB在$queryStats
部署日志 中记录 操作。默认, MongoDB仅记录$queryStats
操作的调用,而不记录操作的输出。 对于包含transformIdentifiers
选项的$queryStats
操作,您可以指定日志条目中是否包含转换后的输出。
在日志中包含$queryStats
输出可提供有关特定$queryStats
操作的更多信息,但可能会对集群性能产生负面影响,因为日志更新需要更多时间和资源。
关于此任务
当 MongoDB 记录$queryStats
输出时,结果将被编辑和匿名化。 $queryStats
输出不包含文字或字段值。
有关转换后的$queryStats
输出的示例,请参阅转换后的示例。
步骤
1
在MongoDB Atlas用户界面中,转到项目的Clusters 页面。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含所需项目的组织。
如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。
如果尚未显示,请单击侧边栏中的Clusters 。
会显示集群页面。
示例
以下示例显示了包含$queryStats
输出时日志消息的差异。
注意
为了便于阅读,对示例日志条目进行了重新格式化。
$queryStats
输出已省略(默认行为)
{ "t":{"$date":"2023-11-27T20:58:59.212+00:00"},"s":"D1", "c":"QRYSTATS", "id":7808300, "ctx":"conn31","msg":"Logging invocation $queryStats","attr":{"commandSpec":{"transformIdentifiers":{"algorithm":"hmac-sha-256","hmacKey":"###"}} }
$queryStats
输出包含
{ "t":{"$date":"2023-11-27T20:58:59.212+00:00"},"s":"D1", "c":"QRYSTATS", "id":7808300, "ctx":"conn31","msg":"Logging invocation $queryStats","attr":{"commandSpec":{"transformIdentifiers":{"algorithm":"hmac-sha-256","hmacKey":"###"}} } { "t":{"$date":"2023-11-27T20:58:59.212+00:00"},"s":"D3", "c":"QRYSTATS", "id":7808301, "ctx":"conn31","msg":"Logging all outputs of $queryStats","attr":{"thisOutput":"{key: {queryShape: {cmdNs: {db: \"hYt+nW/sr1/Zc3YR8nlGWFoesJdvywkw+cR9rMGzXU4=\", coll: \"TRx6R3rvstYgX96gNmeOi5E3QVsOqzRbv7A9j3q7OvM=\"}, command: \"find\", filter: {Wb/Uu22DzKZ/Os+ZvLgPKFKGZPV4cIMZ3Ybv1HfYih4=: {$lt: \"?date\"}}, projection: {r5zQZllsGoqQuQp4Jm0eH2M6RrMqH84KHowcFaiverg=: true}, sort: {r5zQZllsGoqQuQp4Jm0eH2M6RrMqH84KHowcFaiverg=: 1}}, readConcern: {}, collectionType: \"nonExistent\"}, metrics: {lastExecutionMicros: 208, execCount: 21, totalExecMicros: {sum: 6079, max: 1875, min: 198, sumOfSquares: 4401645}, firstResponseExecMicros: {sum: 6079, max: 1875, min: 198, sumOfSquares: 4401645}, docsReturned: {sum: 0, max: 0, min: 0, sumOfSquares: 0}, firstSeenTimestamp: 2023-11-27T19:15:51.317Z, latestSeenTimestamp: 2023-11-27T20:55:51.309Z}, asOf: 2023-11-27T20:58:59.212Z}"} } { "t":{"$date":"2023-11-27T20:58:59.213+00:00"},"s":"D3", "c":"QRYSTATS", "id":7808301, "ctx":"conn31","msg":"Logging all outputs of $queryStats","attr":{"thisOutput":"{key: {queryShape: {cmdNs: {db: \"j+Caz+gxt7vl++gmeCAWrvyhDL17WaNrSIDi6Au7VI0=\", coll: \"f/LCkK/kVEbt4fk2NNbyDPhxas+kzCLLcVbjeNBbhyg=\"}, let: {pUZAyEEImSXcu8deG05tfIf6F/H92YsFnkZXIeRQtgc=: \"?number\"}, command: \"aggregate\", pipeline: [{$group: {_id: \"?number\", 5E6FSc5VxCvIZK0jrqkY3k3aX51jSc73hQwO/8kH0lo=: {$sum: \"?number\"}}}], explain: true, allowDiskUse: false}, client: {driver: {name: \"nodejs|mongosh\", version: \"5.1.0\"}, os: {type: \"Darwin\", name: \"darwin\", architecture: \"arm64\", version: \"22.6.0\"}, platform: \"Node.js v16.19.1, LE (unified)\", version: \"5.1.0|1.8.0\", application: {name: \"mongosh 1.8.0\"}}, collectionType: \"collection\", cursor: {batchSize: \"?number\"}}, metrics: {lastExecutionMicros: 0, execCount: 1, totalExecMicros: {sum: 0, max: 0, min: 0, sumOfSquares: 0}, firstResponseExecMicros: {sum: 0, max: 0, min: 0, sumOfSquares: 0}, docsReturned: {sum: 0, max: 0, min: 0, sumOfSquares: 0}, firstSeenTimestamp: 2023-11-27T19:31:36.463Z, latestSeenTimestamp: 2023-11-27T19:31:36.463Z}, asOf: 2023-11-27T20:58:59.213Z}"} } // Additional $queryStats output...