Skip to content

Commit 49f381a

Browse files
authored
Merge pull request #231118 from seesharprun/cosmos-tutorial-query-code-review
Cosmos DB | NoSQL query tutorial copy edit
2 parents dbc844f + b0460ec commit 49f381a

File tree

1 file changed

+81
-78
lines changed

1 file changed

+81
-78
lines changed

articles/cosmos-db/nosql/tutorial-query.md

Lines changed: 81 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,155 @@
11
---
2-
title: 'Tutorial: How to query with SQL in Azure Cosmos DB?'
3-
description: 'Tutorial: Learn how to query with SQL queries in Azure Cosmos DB using the query playground'
2+
title: |
3+
Tutorial: Query data
4+
titleSuffix: Azure Cosmos DB for NoSQL
5+
description: In this tutorial, learn how to query data in Azure Cosmos DB for NoSQL with the built-in query syntax using the Data Explorer.
46
author: seesharprun
57
ms.author: sidandrews
68
ms.reviewer: mjbrown
79
ms.service: cosmos-db
810
ms.subservice: nosql
911
ms.custom: tutorial-develop, mvc, ignite-2022
1012
ms.topic: tutorial
11-
ms.date: 08/26/2021
13+
ms.date: 03/16/2023
1214
---
1315

14-
# Tutorial: Query Azure Cosmos DB by using the API for NoSQL
16+
# Tutorial: Query data in Azure Cosmos DB for NoSQL
17+
1518
[!INCLUDE[NoSQL](../includes/appliesto-nosql.md)]
1619

17-
The Azure Cosmos DB [API for NoSQL](../introduction.md) supports querying documents using SQL. This article provides a sample document and two sample SQL queries and results.
20+
[Azure Cosmos DB for NoSQL](../introduction.md) supports querying documents using the built-in query syntax. This article provides a sample document and two sample queries and results.
1821

19-
This article covers the following tasks:
22+
This article covers the following tasks:
2023

2124
> [!div class="checklist"]
22-
> * Querying data with SQL
25+
>
26+
> - Query NoSQL data with the built-in query syntax
27+
>
28+
29+
## Prerequisites
30+
31+
This tutorial assumes you have an Azure Cosmos DB account, database, and container.
32+
33+
Don't have any of those resources? Complete this quickstart: [Create an Azure Cosmos DB account, database, container, and items from the Azure portal](quickstart-portal.md).
34+
35+
You can run the queries using the [Azure Cosmos DB Explorer](../data-explorer.md) in the Azure portal. You can also run queries by using the [REST API](/rest/api/cosmos-db/) or [various SDKs](sdk-dotnet-v3.md).
36+
37+
For more information about queries, see [setting started with queries](query/getting-started.md).
2338

2439
## Sample document
2540

26-
The SQL queries in this article use the following sample document.
41+
The queries in this article use the following sample document.
2742

2843
```json
2944
{
3045
"id": "WakefieldFamily",
3146
"parents": [
32-
{ "familyName": "Wakefield", "givenName": "Robin" },
33-
{ "familyName": "Miller", "givenName": "Ben" }
47+
{ "familyName": "Wakefield", "givenName": "Robin" },
48+
{ "familyName": "Miller", "givenName": "Ben" }
3449
],
3550
"children": [
36-
{
37-
"familyName": "Merriam",
38-
"givenName": "Jesse",
39-
"gender": "female", "grade": 1,
40-
"pets": [
41-
{ "givenName": "Goofy" },
42-
{ "givenName": "Shadow" }
43-
]
44-
},
45-
{
46-
"familyName": "Miller",
47-
"givenName": "Lisa",
48-
"gender": "female",
49-
"grade": 8 }
51+
{
52+
"familyName": "Merriam",
53+
"givenName": "Jesse",
54+
"gender": "female", "grade": 1,
55+
"pets": [
56+
{ "givenName": "Goofy" },
57+
{ "givenName": "Shadow" }
58+
]
59+
},
60+
{
61+
"familyName": "Miller",
62+
"givenName": "Lisa",
63+
"gender": "female",
64+
"grade": 8
65+
}
5066
],
5167
"address": { "state": "NY", "county": "Manhattan", "city": "NY" },
5268
"creationDate": 1431620462,
5369
"isRegistered": false
5470
}
5571
```
5672

57-
## Where can I run SQL queries?
58-
59-
You can run queries using the Data Explorer in the Azure portal and via the [REST API and SDKs](sdk-dotnet-v2.md).
60-
61-
For more information about SQL queries, see:
62-
* [SQL query and SQL syntax](query/getting-started.md)
63-
64-
## Prerequisites
73+
## Select all fields and apply a filter
6574

66-
This tutorial assumes you have an Azure Cosmos DB account and collection. Don't have any of those resources? Complete the [5-minute quickstart](quickstart-portal.md).
75+
Given the sample family document, the following query returns the documents where the ID field matches `WakefieldFamily`. Since it's a `SELECT *` statement, the output of the query is the complete JSON document:
6776

68-
## Example query 1
69-
70-
Given the sample family document above, following SQL query returns the documents where the ID field matches `WakefieldFamily`. Since it's a `SELECT *` statement, the output of the query is the complete JSON document:
71-
72-
**Query**
77+
Query:
7378

7479
```sql
75-
SELECT *
76-
FROM Families f
77-
WHERE f.id = "WakefieldFamily"
80+
SELECT *
81+
FROM Families f
82+
WHERE f.id = "WakefieldFamily"
7883
```
7984

80-
**Results**
85+
Results:
8186

8287
```json
8388
{
8489
"id": "WakefieldFamily",
8590
"parents": [
86-
{ "familyName": "Wakefield", "givenName": "Robin" },
87-
{ "familyName": "Miller", "givenName": "Ben" }
91+
{ "familyName": "Wakefield", "givenName": "Robin" },
92+
{ "familyName": "Miller", "givenName": "Ben" }
8893
],
8994
"children": [
90-
{
91-
"familyName": "Merriam",
92-
"givenName": "Jesse",
93-
"gender": "female", "grade": 1,
94-
"pets": [
95-
{ "givenName": "Goofy" },
96-
{ "givenName": "Shadow" }
97-
]
98-
},
99-
{
100-
"familyName": "Miller",
101-
"givenName": "Lisa",
102-
"gender": "female",
103-
"grade": 8 }
95+
{
96+
"familyName": "Merriam",
97+
"givenName": "Jesse",
98+
"gender": "female", "grade": 1,
99+
"pets": [
100+
{ "givenName": "Goofy" },
101+
{ "givenName": "Shadow" }
102+
]
103+
},
104+
{
105+
"familyName": "Miller",
106+
"givenName": "Lisa",
107+
"gender": "female",
108+
"grade": 8
109+
}
104110
],
105111
"address": { "state": "NY", "county": "Manhattan", "city": "NY" },
106112
"creationDate": 1431620462,
107113
"isRegistered": false
108114
}
109115
```
110116

111-
## Example query 2
117+
## Select a cross-product of a child collection field
112118

113119
The next query returns all the given names of children in the family whose ID matches `WakefieldFamily`.
114120

115-
**Query**
121+
Query:
116122

117123
```sql
118-
SELECT c.givenName
119-
FROM Families f
120-
JOIN c IN f.children
121-
WHERE f.id = 'WakefieldFamily'
124+
SELECT c.givenName
125+
FROM Families f
126+
JOIN c IN f.children
127+
WHERE f.id = 'WakefieldFamily'
122128
```
123129

124-
**Results**
130+
Results:
125131

126-
```
132+
```json
127133
[
128-
{
129-
"givenName": "Jesse"
130-
},
131-
{
132-
"givenName": "Lisa"
133-
}
134+
{
135+
"givenName": "Jesse"
136+
},
137+
{
138+
"givenName": "Lisa"
139+
}
134140
]
135141
```
136142

137-
138143
## Next steps
139144

140145
In this tutorial, you've done the following tasks:
141146

142147
> [!div class="checklist"]
143-
> * Learned how to query using SQL
148+
>
149+
> - Learned how to query using the built-in query syntax
150+
>
144151
145152
You can now proceed to the next tutorial to learn how to distribute your data globally.
146153

147154
> [!div class="nextstepaction"]
148155
> [Distribute your data globally](tutorial-global-distribution.md)
149-
150-
Trying to do capacity planning for a migration to Azure Cosmos DB? You can use information about your existing database cluster for capacity planning.
151-
* If all you know is the number of vcores and servers in your existing database cluster, read about [estimating request units using vCores or vCPUs](../convert-vcore-to-request-unit.md)
152-
* If you know typical request rates for your current database workload, read about [estimating request units using Azure Cosmos DB capacity planner](estimate-ru-with-capacity-planner.md)

0 commit comments

Comments
 (0)