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
+40-30Lines changed: 40 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,12 +12,12 @@ ms.author: dech
12
12
# Quickstart: Use Node.js to connect and query data from Azure Cosmos DB SQL API account
13
13
14
14
> [!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)
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)
21
21
22
22
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
23
@@ -33,34 +33,34 @@ For this quickstart purpose, you can use the [try Azure Cosmos DB for free](http
33
33
34
34
1. Navigate to the [try Azure Cosmos DB for free](https://azure.microsoft.com/try/cosmosdb/) page.
35
35
36
-
1. Choose the **SQL** API account and select **Create**. Sign-in using your Microsoft account such as outlook.
36
+
1. Choose the **SQL** API account and select **Create**. Sign-in using your Microsoft account.
37
37
38
38
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
39
40
40
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
41
42
42
## Add a container
43
43
44
-
You can now use the Data Explorer tool in the Azure portal to create a database and container.
44
+
You can now use the Data Explorer tool in the Azure portal to create a database and container.
45
45
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.
46
+
1. Select **Data Explorer** > **New Container**.
49
47
50
-

48
+
The **Add Container** area is displayed on the far right, you may need to scroll right to see it.
49
+
50
+

51
51
52
52
2. In the **Add container** page, enter the settings for the new container.
53
53
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. |
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.
64
64
65
65
## Add sample data
66
66
@@ -86,9 +86,21 @@ This step is optional. If you're interested in learning how the Azure Cosmos dat
86
86
87
87
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
88
89
+
The Cosmos DB JavaScript SDK is called "@azure/cosmos" and can be installed from npm...
90
+
91
+
```bash
92
+
npm install @azure/cosmos
93
+
```
94
+
89
95
The following snippets are all taken from the _app.js_ file.
90
96
91
-
- The `CosmosClient` object is initialized.
97
+
- The `CosmosClient` is imported from the `@azure/cosmos` npm package.
@@ -117,8 +129,6 @@ The following snippets are all taken from the _app.js_ file.
117
129
const { resources:results } =awaitcontainer.items
118
130
.query(querySpec)
119
131
.fetchAll();
120
-
121
-
return results;
122
132
```
123
133
124
134
- Create a new item
@@ -136,8 +146,6 @@ The following snippets are all taken from the _app.js_ file.
136
146
const { resource:itemToUpdate } =await container
137
147
.item(id, category)
138
148
.replace(itemToUpdate);
139
-
140
-
return result;
141
149
```
142
150
143
151
- Delete an item
@@ -169,11 +177,13 @@ Now go back to the Azure portal to get the connection string details of your Azu
169
177
170
178
## Run the app
171
179
172
-
1. Run `npm install` in a terminal to install required npm modules
180
+
1. Run `npm install` in a terminal to install the "@azure/cosmos" npm package
173
181
174
182
2. Run `node app.js` in a terminal to start your node application.
175
183
176
-
You can now go back to Data Explorer, modify, and work with this new data.
184
+
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.
185
+
186
+
You can continue to experiment with this sample application or go back to Data Explorer, modify, and work with your data.
177
187
178
188
## Review SLAs in the Azure portal
179
189
@@ -184,4 +194,4 @@ You can now go back to Data Explorer, modify, and work with this new data.
184
194
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
195
186
196
> [!div class="nextstepaction"]
187
-
> [Import data into Azure Cosmos DB](import-data.md)
197
+
> [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