Docs HomeMongoDB Manual

$listSampledQueries

Definition定义

$listSampledQueries

Returns sampled queries for all collections or a specific collection. 返回所有集合或特定集合的采样查询。Sampled queries are used by the analyzeShardKey command to calculate metrics about the read and write distribution of a shard key.analyzeShardKey命令使用采样查询来计算有关分片键的读写分布的度量。

Syntax语法

$listSampledQueries has this syntax:具有以下语法:

{
$listSampledQueries: { namespace: <namespace> }
}

Behavior行为

  • To list sampled queries for a single collection, specify the collection in the namespace argument.若要列出单个集合的采样查询,请在namespace参数中指定集合。
  • To list sampled queries for all collections, omit the namespace argument.若要列出所有集合的采样查询,请省略namespace参数。

Access Control访问控制

$listSampledQueries requires the clusterMonitor role on the cluster.需要群集上的clusterMonitor角色。

Limitations局限性

  • You cannot use $listSampledQueries on Atlas multitenant configurations.不能在Atlas多租户配置上使用$listSampledQueries
  • You cannot use $listSampledQueries on standalone deployments.不能在独立部署上使用$listSampledQueries
  • You cannot use $listSampledQueries directly against a --shardsvr replica set. When running on a sharded cluster, $listSampledQueries must run against a mongos.不能直接对--shardsvr副本集使用$listSampledQueries。在分片集群上运行时,$listSampledQueries必须针对mongos运行。

Examples实例

List Sampled Queries for All Collections列出所有集合的采样查询

The following aggregation operation lists all sampled queries for all collections in the replica set:以下聚合操作列出了副本集中所有集合的所有采样查询:

db.aggregate( [  { $listSampledQueries: {  } } ] )

List Sampled Queries for A Specific Collection列出特定集合的采样查询

The following aggregation operation lists all sampled queries for a post collections on the social database:以下聚合操作列出了social数据库上post集合的所有采样查询:

db.aggregate( [  { $listSampledQueries: { namespace: "social.post" } } ] )

Output输出

The output fields differ for read and write queries.读查询和写查询的输出字段不同。

Read Queries读取查询

{
_id: <uuid>,
ns: "<database>.<collection>",
collectionUuid: <collUUID>,
cmdName: <find|aggregate|count|distinct>,
cmd: {
filter: <object>,
collation: <object>,
let: <object>
},
expireAt: <date>
}
Field Name字段名称Type类型Description描述
_idUUIDSample ID for the query.查询的示例ID。
nsstringNamespace of the sampled collection.采样集合的命名空间。
collectionUuidUUIDID of the sampled collection.采样集合的ID。
cmdNamestringName of the sampled command. Can be one of: 采样命令的名称。可以是以下其中之一:
  • "find"
  • "aggregate"
  • "count"
  • "distinct"
cmd.filterobjectFilter the command ran with, if applicable.筛选使用运行的命令(如果适用)。
cmd.collationobjectCollation the command ran with, if applicable.运行命令时使用的排序规则(如果适用)。
cmd.letobjectCustom variables the command ran with, if applicable.命令运行时使用的自定义变量(如果适用)。
expireAtdateDate that the sample expires.样本到期的日期。

Write Queries写入查询

{
_id: <uuid>,
ns: "<database>.<collection>",
collectionUuid: <collUUID>,
cmdName: <update|delete|findAndModify>,
cmd: <object>,
expireAt: <date>
}
Field Name字段名称Type类型Description描述
_idUUIDSample ID for the query.查询的示例ID。
nsstringNamespace of the sampled collection.采样集合的命名空间。
collectionUuidUUIDID of the sampled collection.采样集合的ID。
cmdNamestringName of the sampled command. Can be one of: 采样命令的名称。可以是以下其中之一:
  • "update"
  • "delete"
  • "findAndModify"
cmdobjectCommand object命令对象
expireAtdateDate that the sample expires.样本到期的日期。