From 394f8df48ac507e17829bf23b0ad817207caedc0 Mon Sep 17 00:00:00 2001 From: Naomi Pentrel <5212232+npentrel@users.noreply.github.com> Date: Fri, 21 Mar 2025 14:43:13 +0100 Subject: [PATCH 1/3] DOCS-3747: Add example for querying from locations --- assets/scss/_styles_project.scss | 1 + docs/data-ai/data/query.md | 170 ++++++++++++++++++++++--------- 2 files changed, 124 insertions(+), 47 deletions(-) diff --git a/assets/scss/_styles_project.scss b/assets/scss/_styles_project.scss index 9c92bddba5..33bcab456c 100644 --- a/assets/scss/_styles_project.scss +++ b/assets/scss/_styles_project.scss @@ -3249,6 +3249,7 @@ div.tablestep > div.tablestep-number { div.tablestep > div.tablestep-content { width: 100%; + overflow: auto; } diff --git a/docs/data-ai/data/query.md b/docs/data-ai/data/query.md index 750e8c29d4..bb6836a638 100644 --- a/docs/data-ai/data/query.md +++ b/docs/data-ai/data/query.md @@ -51,7 +51,7 @@ Then, select either **SQL** or **MQL** from the **Query mode** dropdown menu on {{% tablestep number=2 %}} **Run your query** -This example query returns 5 readings from a component called `my-sensor`: +This example query returns 5 readings from all machines in your current organization where the component is called `my-sensor`: {{< tabs >}} {{% tab name="SQL" %}} @@ -73,65 +73,141 @@ WHERE component_name = 'my-sensor' LIMIT 5 {{% /tab %}} {{< /tabs >}} -{{% /tablestep %}} -{{% tablestep number=3 %}} -**Review results** -Click **Run query** when ready to perform your query and get matching results. -Query results are displayed as a [JSON array](https://json-schema.org/understanding-json-schema/reference/array) below your query. - -{{% expand "See examples" %}} +{{% expand "Click to see an example that filters by component name and column names." %}} -- The following shows a SQL query that filters by component name and specific column names, and its returned results: +{{< tabs >}} +{{% tab name="SQL" %}} - ```sh {class="command-line" data-prompt="$" data-output="3-80"} - SELECT time_received, data, tags FROM readings - WHERE component_name = 'PM_sensor' LIMIT 2 - [ - { - "time_received": "2024-07-30 00:04:02.144 +0000 UTC", - "data": { - "readings": { - "units": "μg/m³", - "pm_10": 7.6, - "pm_2.5": 5.7 - } - }, - "tags": [ - "air-quality" - ] +```sh {class="command-line" data-prompt="$" data-output="3-80"} +SELECT time_received, data, tags FROM readings +WHERE component_name = 'PM_sensor' LIMIT 2 +[ +{ + "time_received": "2024-07-30 00:04:02.144 +0000 UTC", + "data": { + "readings": { + "units": "μg/m³", + "pm_10": 7.6, + "pm_2.5": 5.7 + } }, + "tags": [ + "air-quality" + ] +}, +{ + "time_received": "2024-07-30 00:37:22.192 +0000 UTC", + "data": { + "readings": { + "pm_2.5": 9.3, + "units": "μg/m³", + "pm_10": 11.5 + } + }, + "tags": [ + "air-quality" + ] +} +] +``` + +{{% /tab %}} +{{% tab name="MQL" %}} + +```sh {class="command-line" data-prompt="$" data-output="16-80"} +[ { - "time_received": "2024-07-30 00:37:22.192 +0000 UTC", - "data": { - "readings": { - "pm_2.5": 9.3, - "units": "μg/m³", - "pm_10": 11.5 - } - }, - "tags": [ - "air-quality" - ] + $match: { + component_name: "PM_sensor" + } + },{ + $limit: 2 + }, { + $project: { + time_received: 1, + data: 1, + tags: 1 + } } +] +[ +{ + "time_received": "2024-07-30 00:04:02.144 +0000 UTC", + "data": { + "readings": { + "units": "μg/m³", + "pm_10": 7.6, + "pm_2.5": 5.7 + } + }, + "tags": [ + "air-quality" + ] +}, +{ + "time_received": "2024-07-30 00:37:22.192 +0000 UTC", + "data": { + "readings": { + "pm_2.5": 9.3, + "units": "μg/m³", + "pm_10": 11.5 + } + }, + "tags": [ + "air-quality" ] - ``` +} +] +``` -- The following shows a SQL query that returns a count of records matching the search criteria: +{{% /tab %}} +{{< /tabs >}} + +{{% /expand %}} +{{% expand "Click to see an example that returns a count of records that match a component name from a specific location." %}} + +{{< tabs >}} +{{% tab name="SQL" %}} + +```sh {class="command-line" data-prompt="$" data-output="3-80"} +SELECT count(*) FROM readings +WHERE component_name = 'PM_sensor' AND location_id = 'ab1cd23e4f' +[ +{ + "_1": 111550 +} +] +``` - ```sh {class="command-line" data-prompt="$" data-output="3-80"} - SELECT count(*) FROM readings - WHERE component_name = 'PM_sensor' - [ +{{% /tab %}} +{{% tab name="MQL" %}} + +```sh {class="command-line" data-prompt="$" data-output="11"} +[ { - "_1": 111550 + $match: { + location_id: "ab1cd23e4f", + component_name: "PM_sensor" + } + },{ + $count: "count" } - ] - ``` +] +{ count: 111550 } +``` -For more information on MQL syntax, see the [MQL (MongoDB Query Language)](https://www.mongodb.com/docs/manual/tutorial/query-documents/) documentation. +{{% /tab %}} +{{< /tabs >}} -{{% /expand%}} +{{% /expand %}} + +{{% /tablestep %}} +{{% tablestep number=3 %}} +**Review results** + +Click **Run query** when ready to perform your query and get matching results. +Query results are displayed as a [JSON array](https://json-schema.org/understanding-json-schema/reference/array) below your query. {{% /tablestep %}} {{< /table >}} From 086d2f8c06d2d14042176308fe4d959f745a6df6 Mon Sep 17 00:00:00 2001 From: Naomi Pentrel <5212232+npentrel@users.noreply.github.com> Date: Mon, 24 Mar 2025 11:31:47 +0100 Subject: [PATCH 2/3] Update docs/data-ai/data/query.md Co-authored-by: Jessamy Taylor <75634662+JessamyT@users.noreply.github.com> --- docs/data-ai/data/query.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/data-ai/data/query.md b/docs/data-ai/data/query.md index bb6836a638..ea6b110e35 100644 --- a/docs/data-ai/data/query.md +++ b/docs/data-ai/data/query.md @@ -51,7 +51,7 @@ Then, select either **SQL** or **MQL** from the **Query mode** dropdown menu on {{% tablestep number=2 %}} **Run your query** -This example query returns 5 readings from all machines in your current organization where the component is called `my-sensor`: +This example query returns the last 5 readings from any components named `my-sensor` in your organization: {{< tabs >}} {{% tab name="SQL" %}} From 7dfde0b63c579ab9cef06eb804bb3446f20665a7 Mon Sep 17 00:00:00 2001 From: Naomi Pentrel <5212232+npentrel@users.noreply.github.com> Date: Mon, 24 Mar 2025 11:32:17 +0100 Subject: [PATCH 3/3] Update docs/data-ai/data/query.md Co-authored-by: Jessamy Taylor <75634662+JessamyT@users.noreply.github.com> --- docs/data-ai/data/query.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/data-ai/data/query.md b/docs/data-ai/data/query.md index ea6b110e35..e8ca14cb39 100644 --- a/docs/data-ai/data/query.md +++ b/docs/data-ai/data/query.md @@ -174,9 +174,9 @@ WHERE component_name = 'PM_sensor' LIMIT 2 SELECT count(*) FROM readings WHERE component_name = 'PM_sensor' AND location_id = 'ab1cd23e4f' [ -{ - "_1": 111550 -} + { + "_1": 111550 + } ] ```