You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cosmos-db/create-sql-api-nodejs.md
+42-31Lines changed: 42 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,15 +9,17 @@ ms.topic: quickstart
9
9
ms.date: 02/26/2020
10
10
ms.author: dech
11
11
---
12
+
12
13
# Quickstart: Use Node.js to connect and query data from Azure Cosmos DB SQL API account
13
14
14
15
> [!div class="op_single_selector"]
15
-
> *[.NET V3](create-sql-api-dotnet.md)
16
-
> *[.NET V4](create-sql-api-dotnet-V4.md)
17
-
> *[Java](create-sql-api-java.md)
18
-
> *[Node.js](create-sql-api-nodejs.md)
19
-
> *[Python](create-sql-api-python.md)
20
-
> *[Xamarin](create-sql-api-xamarin-dotnet.md)
16
+
>
17
+
> -[.NET V3](create-sql-api-dotnet.md)
18
+
> -[.NET V4](create-sql-api-dotnet-V4.md)
19
+
> -[Java](create-sql-api-java.md)
20
+
> -[Node.js](create-sql-api-nodejs.md)
21
+
> -[Python](create-sql-api-python.md)
22
+
> -[Xamarin](create-sql-api-xamarin-dotnet.md)
21
23
22
24
In this quickstart, you create and manage an Azure Cosmos DB SQL API account from the Azure portal, and by using a Node.js app cloned from GitHub. Azure Cosmos DB is a multi-model database service that lets you quickly create and query document, table, key-value, and graph databases with global distribution and horizontal scale capabilities.
23
25
@@ -33,34 +35,34 @@ For this quickstart purpose, you can use the [try Azure Cosmos DB for free](http
33
35
34
36
1. Navigate to the [try Azure Cosmos DB for free](https://azure.microsoft.com/try/cosmosdb/) page.
35
37
36
-
1. Choose the **SQL** API account and select **Create**. Sign-in using your Microsoft account such as outlook.
38
+
1. Choose the **SQL** API account and select **Create**. Sign-in using your Microsoft account.
37
39
38
40
1. After the sign-in is successful, your Azure Cosmos account should be ready. Select **Open in the Azure portal** to open the newly created account.
39
41
40
42
The "try Azure Cosmos DB for free" option doesn't require an Azure subscription and it offers you an Azure Cosmos account for a limited period of 30 days. If you want to use the Azure Cosmos account for a longer period, you should instead [create the account](create-cosmosdb-resources-portal.md#create-an-azure-cosmos-db-account) within your Azure subscription.
41
43
42
44
## Add a container
43
45
44
-
You can now use the Data Explorer tool in the Azure portal to create a database and container.
46
+
You can now use the Data Explorer tool in the Azure portal to create a database and container.
47
+
48
+
1. Select **Data Explorer** > **New Container**.
45
49
46
-
1. Select **Data Explorer** > **New Container**.
47
-
48
-
The **Add Container** area is displayed on the far right, you may need to scroll right to see it.
50
+
The **Add Container** area is displayed on the far right, you may need to scroll right to see it.
49
51
50
-

52
+

51
53
52
54
2. In the **Add container** page, enter the settings for the new container.
53
55
54
-
|Setting|Suggested value|Description
55
-
|---|---|---|
56
-
|**Database ID**|Tasks|Enter *Tasks* as the name for the new database. Database names must contain from 1 through 255 characters, and they cannot contain `/, \\, #, ?`, or a trailing space. Check the **Provision database throughput** option, it allows you to share the throughput provisioned to the database across all the containers within the database. This option also helps with cost savings. |
57
-
|**Throughput**|400|Leave the throughput at 400 request units per second (RU/s). If you want to reduce latency, you can scale up the throughput later.|
58
-
|**Container ID**|Items|Enter *Items* as the name for your new container. Container IDs have the same character requirements as database names.|
59
-
|**Partition key**| /category| The sample described in this article uses */category* as the partition key.|
60
-
61
-
In addition to the preceding settings, you can optionally add **Unique keys** for the container. Let's leave the field empty in this example. Unique keys provide developers with the ability to add a layer of data integrity to the database. By creating a unique key policy while creating a container, you ensure the uniqueness of one or more values per partition key. To learn more, refer to the [Unique keys in Azure Cosmos DB](unique-keys.md) article.
62
-
63
-
Select **OK**. The Data Explorer displays the new database and container.
|**Database ID**|Tasks|Enter _Tasks_ as the name for the new database. Database names must contain from 1 through 255 characters, and they cannot contain `/, \\, #, ?`, or a trailing space. Check the **Provision database throughput** option, it allows you to share the throughput provisioned to the database across all the containers within the database. This option also helps with cost savings. |
59
+
|**Throughput**|400|Leave the throughput at 400 request units per second (RU/s). If you want to reduce latency, you can scale up the throughput later.|
60
+
|**Container ID**|Items|Enter _Items_ as the name for your new container. Container IDs have the same character requirements as database names.|
61
+
|**Partition key**| /category| The sample described in this article uses _/category_ as the partition key.|
62
+
63
+
In addition to the preceding settings, you can optionally add **Unique keys** for the container. Let's leave the field empty in this example. Unique keys provide developers with the ability to add a layer of data integrity to the database. By creating a unique key policy while creating a container, you ensure the uniqueness of one or more values per partition key. To learn more, refer to the [Unique keys in Azure Cosmos DB](unique-keys.md) article.
64
+
65
+
Select **OK**. The Data Explorer displays the new database and container.
64
66
65
67
## Add sample data
66
68
@@ -86,9 +88,21 @@ This step is optional. If you're interested in learning how the Azure Cosmos dat
86
88
87
89
If you're familiar with the previous version of the SQL JavaScript SDK, you may be used to seeing the terms _collection_ and _document_. Because Azure Cosmos DB supports [multiple API models](introduction.md), [version 2.0+ of the JavaScript SDK](https://www.npmjs.com/package/@azure/cosmos) uses the generic terms _container_, which may be a collection, graph, or table, and _item_ to describe the content of the container.
88
90
91
+
The Cosmos DB JavaScript SDK is called "@azure/cosmos" and can be installed from npm...
92
+
93
+
```bash
94
+
npm install @azure/cosmos
95
+
```
96
+
89
97
The following snippets are all taken from the _app.js_ file.
90
98
91
-
- The `CosmosClient` object is initialized.
99
+
- The `CosmosClient` is imported from the `@azure/cosmos` npm package.
@@ -117,8 +131,6 @@ The following snippets are all taken from the _app.js_ file.
117
131
const { resources:results } =awaitcontainer.items
118
132
.query(querySpec)
119
133
.fetchAll();
120
-
121
-
return results;
122
134
```
123
135
124
136
- Create a new item
@@ -136,8 +148,6 @@ The following snippets are all taken from the _app.js_ file.
136
148
const { resource:itemToUpdate } =await container
137
149
.item(id, category)
138
150
.replace(itemToUpdate);
139
-
140
-
return result;
141
151
```
142
152
143
153
- Delete an item
@@ -169,11 +179,13 @@ Now go back to the Azure portal to get the connection string details of your Azu
169
179
170
180
## Run the app
171
181
172
-
1. Run `npm install` in a terminal to install required npm modules
182
+
1. Run `npm install` in a terminal to install the "@azure/cosmos" npm package
173
183
174
184
2. Run `node app.js` in a terminal to start your node application.
175
185
176
-
You can now go back to Data Explorer, modify, and work with this new data.
186
+
3. The two items that you created earlier in this quickstart are listed out. A new item is created. The "isComplete" flag on that item is updated to "true" and then finally, the item is deleted.
187
+
188
+
You can continue to experiment with this sample application or go back to Data Explorer, modify, and work with your data.
177
189
178
190
## Review SLAs in the Azure portal
179
191
@@ -183,5 +195,4 @@ You can now go back to Data Explorer, modify, and work with this new data.
183
195
184
196
In this quickstart, you've learned how to create an Azure Cosmos DB account, create a container using the Data Explorer, and run a Node.js app. You can now import additional data to your Azure Cosmos DB account.
185
197
186
-
> [!div class="nextstepaction"]
187
-
> [Import data into Azure Cosmos DB](import-data.md)
198
+
> [!div class="nextstepaction"][import data into azure cosmos db](import-data.md)
Copy file name to clipboardExpand all lines: includes/cosmos-db-create-sql-api-query-data.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@
11
11
---
12
12
You can use queries in Data Explorer to retrieve and filter your data.
13
13
14
-
1. At the top of the **Documents** tab in Data Explorer, review the default query `SELECT * FROM c`. This query retrieves and displays all documents in the collection in ID order.
14
+
1. At the top of the **Items** tab in Data Explorer, review the default query `SELECT * FROM c`. This query retrieves and displays all documents in the collection in ID order.
15
15
16
16

0 commit comments