Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS-3747: Add example for querying from locations #4117

Merged
merged 3 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/scss/_styles_project.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3249,6 +3249,7 @@ div.tablestep > div.tablestep-number {

div.tablestep > div.tablestep-content {
width: 100%;
overflow: auto;
}


Expand Down
170 changes: 123 additions & 47 deletions docs/data-ai/data/query.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" %}}
Expand All @@ -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 >}}
Expand Down
Loading