|
| 1 | +=================== |
| 2 | +$listSampledQueries |
| 3 | +=================== |
| 4 | + |
| 5 | +.. default-domain:: mongodb |
| 6 | + |
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 2 |
| 11 | + :class: singlecol |
| 12 | + |
| 13 | +Definition |
| 14 | +---------- |
| 15 | + |
| 16 | +.. pipeline:: $listSampledQueries |
| 17 | + |
| 18 | + Returns sampled queries for all collections or a specific |
| 19 | + collection. Sampled queries are used by the |
| 20 | + ``analyzeShardKey`` command to calculate metrics about the read and |
| 21 | + write distribution of a shard key. |
| 22 | + |
| 23 | +Syntax |
| 24 | +------ |
| 25 | + |
| 26 | +``$listSampledQueries`` has this syntax: |
| 27 | + |
| 28 | +.. code-block:: javascript |
| 29 | + |
| 30 | + { |
| 31 | + $listSampledQueries: { namespace: <namespace> } |
| 32 | + } |
| 33 | + |
| 34 | +Behavior |
| 35 | +-------- |
| 36 | + |
| 37 | +- To list sampled queries for a single collection, specify |
| 38 | + the collection in the ``namespace`` argument. |
| 39 | + |
| 40 | +- To list sampled queries for all collections, omit the ``namespace`` |
| 41 | + argument. |
| 42 | + |
| 43 | +Access Control |
| 44 | +-------------- |
| 45 | + |
| 46 | +``$listSampledQueries`` requires the :authrole:`clusterMonitor` role |
| 47 | +on the cluster. |
| 48 | + |
| 49 | +Limitations |
| 50 | +----------- |
| 51 | + |
| 52 | +- You cannot use ``$listSampledQueries`` on Atlas |
| 53 | + :atlas:`multitenant </docs/atlas/build-multi-tenant-arch/>` |
| 54 | + configurations. |
| 55 | +- You cannot use ``$listSampledQueries`` on standalone deployments. |
| 56 | +- You cannot use ``$listSampledQueries`` directly against a |
| 57 | + :option:`--shardsvr <mongod --shardsvr>` replica set. |
| 58 | + When running on a sharded cluster, ``$listSampledQueries`` |
| 59 | + must run against a ``mongos``. |
| 60 | + |
| 61 | +Examples |
| 62 | +-------- |
| 63 | + |
| 64 | +List Sampled Queries for All Collections |
| 65 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 66 | + |
| 67 | +The following aggregation operation lists all sampled queries for all |
| 68 | +collections in the replica set: |
| 69 | + |
| 70 | +.. code-block:: javascript |
| 71 | + |
| 72 | + db.aggregate( [ { $listSampledQueries: { } } ] ) |
| 73 | + |
| 74 | +List Sampled Queries for A Specific Collection |
| 75 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 76 | + |
| 77 | +The following aggregation operation lists all sampled queries for a |
| 78 | +``post`` collections on the ``social`` database: |
| 79 | + |
| 80 | +.. code-block:: javascript |
| 81 | + |
| 82 | + db.aggregate( [ { $listSampledQueries: { namespace: "social.post" } } ] ) |
| 83 | + |
| 84 | +Output |
| 85 | +------ |
| 86 | + |
| 87 | +The output fields differ for read and write queries. |
| 88 | + |
| 89 | +Read Queries |
| 90 | +~~~~~~~~~~~~ |
| 91 | + |
| 92 | +.. code-block:: none |
| 93 | + :copyable: false |
| 94 | + |
| 95 | + { |
| 96 | + _id: <uuid>, |
| 97 | + ns: "<database>.<collection>", |
| 98 | + collectionUuid: <collUUID>, |
| 99 | + cmdName: <find|aggregate|count|distinct>, |
| 100 | + cmd: { |
| 101 | + filter: <object>, |
| 102 | + collation: <object>, |
| 103 | + let: <object> |
| 104 | + }, |
| 105 | + expireAt: <date> |
| 106 | + } |
| 107 | + |
| 108 | + |
| 109 | +.. list-table:: |
| 110 | + :header-rows: 1 |
| 111 | + |
| 112 | + * - Field Name |
| 113 | + - Type |
| 114 | + - Description |
| 115 | + |
| 116 | + * - ``_id`` |
| 117 | + - UUID |
| 118 | + - Sample ID for the query. |
| 119 | + |
| 120 | + * - ``ns`` |
| 121 | + - string |
| 122 | + - Namespace of the sampled collection. |
| 123 | + |
| 124 | + * - ``collectionUuid`` |
| 125 | + - UUID |
| 126 | + - ID of the sampled collection. |
| 127 | + |
| 128 | + * - ``cmdName`` |
| 129 | + - string |
| 130 | + - Name of the sampled command. Can be one of: |
| 131 | + |
| 132 | + - ``"find"`` |
| 133 | + - ``"aggregate"`` |
| 134 | + - ``"count"`` |
| 135 | + - ``"distinct"`` |
| 136 | + |
| 137 | + * - ``cmd.filter`` |
| 138 | + - object |
| 139 | + - Filter the command ran with, if applicable. |
| 140 | + |
| 141 | + * - ``cmd.collation`` |
| 142 | + - object |
| 143 | + - Collation the command ran with, if applicable. |
| 144 | + |
| 145 | + * - ``cmd.let`` |
| 146 | + - object |
| 147 | + - Custom variables the command ran with, if applicable. |
| 148 | + |
| 149 | + * - ``expireAt`` |
| 150 | + - date |
| 151 | + - Date that the sample expires. |
| 152 | + |
| 153 | +Write Queries |
| 154 | +~~~~~~~~~~~~~ |
| 155 | + |
| 156 | +.. code-block:: none |
| 157 | + :copyable: false |
| 158 | + |
| 159 | + { |
| 160 | + _id: <uuid>, |
| 161 | + ns: "<database>.<collection>", |
| 162 | + collectionUuid: <collUUID>, |
| 163 | + cmdName: <update|delete|findAndModify>, |
| 164 | + cmd: <object>, |
| 165 | + expireAt: <date> |
| 166 | + } |
| 167 | + |
| 168 | +.. list-table:: |
| 169 | + :header-rows: 1 |
| 170 | + |
| 171 | + * - Field Name |
| 172 | + - Type |
| 173 | + - Description |
| 174 | + |
| 175 | + * - ``_id`` |
| 176 | + - UUID |
| 177 | + - Sample ID for the query. |
| 178 | + |
| 179 | + * - ``ns`` |
| 180 | + - string |
| 181 | + - Namespace of the sampled collection. |
| 182 | + |
| 183 | + * - ``collectionUuid`` |
| 184 | + - UUID |
| 185 | + - ID of the sampled collection. |
| 186 | + |
| 187 | + * - ``cmdName`` |
| 188 | + - string |
| 189 | + - Name of the sampled command. Can be one of: |
| 190 | + |
| 191 | + - ``"update"`` |
| 192 | + - ``"delete"`` |
| 193 | + - ``"findAndModify"`` |
| 194 | + |
| 195 | + * - ``cmd`` |
| 196 | + - object |
| 197 | + - Command object |
| 198 | + |
| 199 | + * - ``expireAt`` |
| 200 | + - date |
| 201 | + - Date that the sample expires. |
0 commit comments