Skip to content

Commit ab2419a

Browse files
DOCSP-20351 Add indexed matchComments field to query history (#222)
* DOCSP-20351 Add indexed matchComments field to query history * DOCSP-20351 updates for review feedback * DOCSP-20351 updates for copy review feedback * DOCSP-20351 remove separate syntax for comment in match * DOCSP-20351 updates for review feedback * DOCSP-20351 updates to the tutorials page * DOCSP-20351 changed field name to queryFilterComments * DOCSP-20351 updates for feedback
1 parent c8d304f commit ab2419a

File tree

4 files changed

+98
-9
lines changed

4 files changed

+98
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ handouts/mongodb-logo-eps-converted-to.pdf
2323
source/figures/
2424
giza.log
2525
backups/*
26+
.vscode/

snooty.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title = "MongoDB Atlas Data Lake"
33

44
intersphinx = ["https://docs.mongodb.com/manual/objects.inv","https://docs.atlas.mongodb.com/objects.inv","https://docs.mongodb.com/database-tools/objects.inv","https://docs.mongodb.com/mongodb-shell/objects.inv"]
55

6-
toc_landing_pages = ["/config/config-data-lake", "/tutorial/getting-started", "/admin/query-with-sql", "/query/query-data-lake", "/tutorial/connect", "/supported-unsupported/mql-support", "/tutorial/configure-connection", "/reference/api/datalakes-api", "/reference/cli/administration-commands", "/reference/pipeline/aggr-pipeline", "/tutorials" ]
6+
toc_landing_pages = ["/config/config-data-lake", "/tutorial/getting-started", "/admin/query-with-sql", "/query/query-data-lake", "/tutorial/connect", "/supported-unsupported/mql-support", "/tutorial/configure-connection", "/tutorials"]
77

88
[constants]
99
adl = "Atlas Data Lake"

source/query/view-query-history.txt

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ query, that contain information about the :manual:`aggregate
2020
</reference/command/aggregate>`, :manual:`find
2121
</reference/command/find/>`, and :manual:`count
2222
</reference/command/count/>` queries that were run in the past 24
23-
hours. To run |qh|, use the :manual:`db.aggregate
23+
hours. You can filter on the fields returned by |qh| in subsequent
24+
pipeline stages such as :pipeline:`$match`.
25+
26+
To run |qh|, use the :manual:`db.aggregate
2427
</reference/method/db.aggregate/#db.aggregate>` helper. |qh| must be
2528
run against the ``admin`` database.
2629

@@ -78,7 +81,7 @@ fields:
7881

7982
.. list-table::
8083
:header-rows: 1
81-
:widths: 10 10 80
84+
:widths: 10 15 75
8285

8386
* - Field
8487
- Type
@@ -122,6 +125,12 @@ fields:
122125
- Error, if any, returned by the query. Note that the query status
123126
``0`` indicates errors. Empty string if query ran successfully.
124127

128+
* - ``queryFilterComments``
129+
- array of strings
130+
- Comment strings included with the ``$comment`` operator inside
131+
the query pipeline. Omitted if the query didn't include the
132+
``$comment`` operator.
133+
125134
* - ``ok``
126135
- int
127136
- Status of the query. Value can be one of the following:
@@ -154,8 +163,14 @@ fields:
154163

155164
.. _adl-query-history-stage-egs:
156165

157-
Example
158-
-------
166+
Examples
167+
--------
168+
169+
The examples below use the ``Database0.Collection0`` collection
170+
described in the :ref:`Get Started tutorial <adl-tutorials>`.
171+
172+
Retrieve Details About the Queries
173+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
159174

160175
For the example below, suppose some of the queries described in the
161176
:ref:`Getting Started tutorial <gst-run-queries>` were run by ``user1``
@@ -304,3 +319,76 @@ following example returns information on the queries that were run by
304319
"ok" : 1,
305320
"background" : true
306321
}
322+
323+
Filter |qh| Output for Specific Queries
324+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
325+
326+
For the example below, suppose a query similar to the following is
327+
run against the ``Database0.Collection0`` collection described in the
328+
:ref:`Getting Started tutorial <adl-tutorials>`. The query includes
329+
unique strings to help identify the query in the results returned by
330+
the |qh| stage. You can attach a comment to a query using the
331+
:manual:`aggregate </reference/command/aggregate/>` command ``comment``
332+
option or the :manual:`$comment </reference/operator/query/comment/>`
333+
operator. This example uses both ways to attach the unique strings with
334+
the query.
335+
336+
.. code-block:: shell
337+
338+
use Database0
339+
db.Collection0.aggregate([ { $match: {"account_id": 557378, "$comment": "test"}},{$sort: {"transactions.symbol": -1}} ],{"comment":"exampleQuery"})
340+
341+
.. tabs::
342+
343+
.. tab:: comment Option Example
344+
:tabid: option
345+
346+
To retrieve the query history using the string value of the
347+
``comment`` option of the :manual:`aggregate
348+
</reference/command/aggregate/>` command, run the following
349+
commands against the ``admin`` database:
350+
351+
.. code-block:: json
352+
353+
use admin
354+
db.aggregate([{$queryHistory: {}}, {$match: {"comment": "exampleQuery"}} ])
355+
356+
.. tab:: $comment Operator Example
357+
:tabid: operator
358+
359+
To retrieve the query history using the string value of the
360+
``$comment`` operator in the :pipeline:`$match` query, run the
361+
following commands against the ``admin`` database.
362+
363+
.. code-block:: json
364+
365+
use admin
366+
db.aggregate([{$queryHistory: {}}, {$match: {queryFilterComments: "test"}}])
367+
368+
|qh| finds the query that included the specified string and returns
369+
results similar to the following:
370+
371+
.. code-block:: json
372+
:copyable: false
373+
374+
[
375+
{
376+
"_id": ObjectId("61e1e4c29e62172566d8e9b6"),
377+
"query": [
378+
{ "$match": { "account_id": 557378, "$comment": "test" } },
379+
{ "$sort": { "transactions.symbol": -1 } }
380+
],
381+
"comment": "exampleQuery",
382+
"appName": "mongosh 1.1.8",
383+
"user": "admin.user1",
384+
"db": "Database0",
385+
"collection": "Collection0",
386+
"opid": ObjectId("16ca3ed2577016e68d60358c"),
387+
"startTime": ISODate("2022-01-14T21:01:27.346Z"),
388+
"endTime": ISODate("2022-01-14T21:01:54.627Z"),
389+
"ok": 1,
390+
"error": "",
391+
"background": false,
392+
"queryFilterComments": [ "test" ]
393+
}
394+
]

source/tutorials.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ following actions:
1414

1515
- `Get MongoDB Data Into Parquet
1616
<https://www.mongodb.com/developer/how-to/mongodb-data-parquet/>`__ -
17-
This tutorial shows you how to use {+adl+} to get data from your
18-
|service| Cluster or |s3| Bucket in to Apache Parquet, which provides
19-
high performance querying capability on cloud object storage.
17+
This tutorial shows you how to use {+adl+} to get data in any format
18+
from your |service| Cluster or |s3| Bucket in to Apache Parquet,
19+
which allows you to query data in the cloud very fast.
2020

2121
- `Query From Multiple MongoDB Databases <https://www.mongodb.com/developer/how-to/query-multiple-databases-with-atlas-data-lake/>`__ -
2222
This tutorial shows you how to use {+adl+} to query data across
@@ -30,4 +30,4 @@ following actions:
3030
- `Copy Data Automatically From MongoDB to an AWS S3 Bucket <https://www.mongodb.com/developer/how-to/automated-continuous-data-copying-from-mongodb-to-s3/>`__ -
3131
This tutorial shows you how to use |service| :atlas:`triggers
3232
</triggers/>` and {+adl+} to write data from your |service| Cluster
33-
to your |aws| |s3| bucket on an automated schedule.
33+
to your |aws| |s3| bucket continuously on a schedule.

0 commit comments

Comments
 (0)