$listSampledQueries
Definition
Syntax
$listSampledQueries has this syntax:
{    $listSampledQueries: { namespace: <namespace> } } 
Behavior
To list sampled queries for a single collection, specify the collection in the
namespaceargument.To list sampled queries for all collections, omit the
namespaceargument.
Access Control
$listSampledQueries requires the clusterMonitor role
on the cluster.
Limitations
You cannot use
$listSampledQuerieson Atlas multi-tenant configurations.You cannot use
$listSampledQuerieson standalone deployments.You cannot use
$listSampledQueriesdirectly against a--shardsvrreplica set. When running on a sharded cluster,$listSampledQueriesmust run against amongos.
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:
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  | 
|---|---|---|
  | UUID  | Sample ID for the query.  | 
  | string  | Namespace of the sampled collection.  | 
  | UUID  | ID of the sampled collection.  | 
  | string  | Name of the sampled command. Can be one of: 
  | 
  | object  | Filter the command ran with, if applicable.  | 
  | object  | Collation the command ran with, if applicable.  | 
  | object  | Custom variables the command ran with, if applicable.  | 
  | date  | Date 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  | 
|---|---|---|
  | UUID  | Sample ID for the query.  | 
  | string  | Namespace of the sampled collection.  | 
  | UUID  | ID of the sampled collection.  | 
  | string  | Name of the sampled command. Can be one of: 
  | 
  | object  | Command object  | 
  | date  | Date that the sample expires.  |