Skip to content

Commit 619a96d

Browse files
Merge pull request #282862 from seesharprun/cosmos-nosql-quickstart-nodejs-typescript
Cosmos DB | Add TypeScript code samples to NoSQL Node.js quickstart
2 parents f6429fd + 786a915 commit 619a96d

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

articles/cosmos-db/nosql/quickstart-nodejs.md

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ ms.author: sidandrews
77
ms.reviewer: mjbrown
88
ms.service: azure-cosmos-db
99
ms.subservice: nosql
10-
ms.devlang: javascript
11-
ms.custom: devx-track-js, devx-track-extended-azdevcli
10+
ms.devlang: typescript
11+
ms.custom: devx-track-js, devx-track-ts, devx-track-extended-azdevcli
1212
ms.topic: quickstart-sdk
13-
ms.date: 06/14/2024
13+
ms.date: 08/01/2024
1414
zone_pivot_groups: azure-cosmos-db-quickstart-env
1515
# CustomerIntent: As a developer, I want to learn the basics of the Node.js library so that I can build applications with Azure Cosmos DB for NoSQL.
1616
---
@@ -152,32 +152,72 @@ The client library is available through the Node Package Manager, as the `@azure
152152
153153
This sample creates a new instance of the `CosmosClient` type and authenticates using a `DefaultAzureCredential` instance.
154154
155+
### [JavaScript](#tab/javascript)
156+
155157
:::code language="javascript" source="~/cosmos-db-nosql-nodejs-quickstart/src/js/cosmos.js" id="create_client" highlight="1,3":::
156158
159+
### [TypeScript](#tab/typescript)
160+
161+
:::code language="typescript" source="~/cosmos-db-nosql-nodejs-quickstart/src/ts/cosmos.ts" id="create_client" highlight="1,3":::
162+
163+
---
164+
157165
### Get a database
158166
159167
Use `client.database` to retrieve the existing database named *`cosmicworks`*.
160168
169+
### [JavaScript](#tab/javascript)
170+
161171
:::code language="javascript" source="~/cosmos-db-nosql-nodejs-quickstart/src/js/cosmos.js" id="get_database":::
162172
173+
### [TypeScript](#tab/typescript)
174+
175+
:::code language="typescript" source="~/cosmos-db-nosql-nodejs-quickstart/src/ts/cosmos.ts" id="get_database":::
176+
177+
---
178+
163179
### Get a container
164180
165181
Retrieve the existing *`products`* container using `database.container`.
166182
183+
### [JavaScript](#tab/javascript)
184+
167185
:::code language="javascript" source="~/cosmos-db-nosql-nodejs-quickstart/src/js/cosmos.js" id="get_container":::
168186
187+
### [TypeScript](#tab/typescript)
188+
189+
:::code language="typescript" source="~/cosmos-db-nosql-nodejs-quickstart/src/ts/cosmos.ts" id="get_container":::
190+
191+
---
192+
169193
### Create an item
170194
171195
Build a new object with all of the members you want to serialize into JSON. In this example, the type has a unique identifier, and fields for category, name, quantity, price, and sale. Create an item in the container using `container.items.upsert`. This method "upserts" the item effectively replacing the item if it already exists.
172196
197+
### [JavaScript](#tab/javascript)
198+
173199
:::code language="javascript" source="~/cosmos-db-nosql-nodejs-quickstart/src/js/cosmos.js" id="create_item" highlight="10":::
174200
201+
### [TypeScript](#tab/typescript)
202+
203+
:::code language="typescript" source="~/cosmos-db-nosql-nodejs-quickstart/src/ts/cosmos.ts" id="create_item" highlight="10":::
204+
205+
---
206+
175207
### Read an item
176208
177209
Perform a point read operation by using both the unique identifier (`id`) and partition key fields. Use `container.item` to get a pointer to an item and `item.read` to efficiently retrieve the specific item.
178210
211+
### [JavaScript](#tab/javascript)
212+
179213
:::code language="javascript" source="~/cosmos-db-nosql-nodejs-quickstart/src/js/cosmos.js" id="read_item" highlight="4":::
180214
215+
### [TypeScript](#tab/typescript)
216+
217+
:::code language="typescript" source="~/cosmos-db-nosql-nodejs-quickstart/src/ts/cosmos.ts" id="read_item" highlight="4":::
218+
219+
---
220+
181221
### Query items
182222
183223
Perform a query over multiple items in a container using `container.items.query`. Find all items within a specified category using this parameterized query:
@@ -188,8 +228,16 @@ SELECT * FROM products p WHERE p.category = @category
188228

189229
Fetch all of the results of the query using `query.fetchAll`. Loop through the results of the query.
190230

231+
### [JavaScript](#tab/javascript)
232+
191233
:::code language="javascript" source="~/cosmos-db-nosql-nodejs-quickstart/src/js/cosmos.js" id="query_items" highlight="2,11":::
192234

235+
### [TypeScript](#tab/typescript)
236+
237+
:::code language="typescript" source="~/cosmos-db-nosql-nodejs-quickstart/src/ts/cosmos.ts" id="query_items" highlight="2,11":::
238+
239+
---
240+
193241
## Related content
194242

195243
- [.NET Quickstart](quickstart-dotnet.md)

0 commit comments

Comments
 (0)