Database Manual / Reference / Query Language / Aggregation Stages / $queryStats

Toggle $queryStats Log Output切换$queryStats日志输出

MongoDB records $queryStats operations in the deployment logs. MongoDB在部署日志中记录$queryStats操作。By default, MongoDB only logs the invocation of $queryStats operations, not the operation's output. 默认情况下,MongoDB只记录$queryStats操作的调用,而不是操作的输出。For $queryStats operations that include the transformIdentifiers option, you can specify whether the transformed output is included in the log entry.对于包含transformIdentifiers选项的$queryStats操作,您可以指定转换后的输出是否包含在日志条目中。

Including $queryStats output in the logs provides more information on specific $queryStats operations, but can negatively impact cluster performance as log updates take more time and resources.在日志中包含$queryStats输出可以提供有关特定$queryStat操作的更多信息,但会对集群性能产生负面影响,因为日志更新需要更多的时间和资源。

About this Task关于此任务

When MongoDB logs $queryStats output, the results are redacted and anonymized. $queryStats output does not contain literals or field values.当MongoDB记录$queryStats输出时,结果会被编辑和匿名化。$queryStats输出不包含文字或字段值。

For an example of transformed $queryStats output, see Transformed Example.有关转换后的$queryStats输出的示例,请参阅转换示例

Steps步骤

1

In the MongoDB Atlas UI, go to the Clusters page for your project.在MongoDB Atlas UI中,转到项目的“集群”页面。

Warning

Navigation Improvements In Progress导航改进正在进行中

We're currently rolling out a new and improved navigation experience. If the following steps don't match your view in the Atlas UI, see the preview Atlas documentation.我们目前正在推出一种新的、改进的导航体验。如果以下步骤与Atlas UI中的视图不匹配,请参阅Atlas预览文档

  1. If it's not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.如果尚未显示,请从导航栏的“组织”菜单中选择包含所需项目的组织。
  2. If it's not already displayed, select your project from the Projects menu in the navigation bar.如果尚未显示,请从导航栏中的“项目”菜单中选择您的项目。
  3. If it's not already displayed, click Clusters in the sidebar.如果尚未显示,请单击侧栏中的“集群”。

    The Clusters page displays.“集群”页面显示。

2

Click Edit Config单击“编辑配置”

3

Select your cluster from the dropdown从下拉列表中选择您的集群

4

Open the Additional Settings dropdown打开“附加设置”下拉菜单

5

Open the More Configuration Options dropdown打开“更多配置选项”下拉菜单

6

Toggle the Enable Logging of Redacted and Anonymized Query Data setting切换“启用编辑和匿名查询数据记录”设置

7

Click Review Changes单击“查看更改”

8

Click Apply Changes单击“应用更改”

Examples示例

The following examples show the differences in log messages when $queryStats output is included.以下示例显示了包含$queryStats输出时日志消息的差异。

Note

The example log entries are reformatted for readability.为了可读性,对示例日志条目进行了重新格式化。

$queryStats Output Omitted (Default Behavior)省略输出(默认行为)

{
"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 Output Included产出包括

{
"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...

Learn More了解更多