Skip to content

Commit 270de19

Browse files
authored
Merge pull request #217125 from seesharprun/cosmos-nosql-python-quickstart-revamp
Cosmos DB | NoSQL Revamp .NET/Python Quickstarts
2 parents 11aecb3 + a9d65aa commit 270de19

9 files changed

+125
-60
lines changed

.openpublishing.publish.config.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,11 +849,17 @@
849849
"branch_mapping": {}
850850
},
851851
{
852-
"path_to_root": "azure-cosmos-dotnet-v3",
852+
"path_to_root": "cosmos-db-nosql-dotnet-samples",
853853
"url": "https://github.com/azure-samples/cosmos-db-nosql-dotnet-samples",
854854
"branch": "main",
855855
"branch_mapping": {}
856856
},
857+
{
858+
"path_to_root": "cosmos-db-nosql-python-samples",
859+
"url": "https://github.com/azure-samples/cosmos-db-nosql-python-samples",
860+
"branch": "main",
861+
"branch_mapping": {}
862+
},
857863
{
858864
"path_to_root": "azure-cosmos-db-table-dotnet-v12",
859865
"url": "https://github.com/Azure-Samples/cosmos-db-table-api-dotnet-samples",

articles/cosmos-db/nosql/how-to-dotnet-create-container.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ To create a container, call one of the following methods:
4242

4343
The following example creates a container asynchronously:
4444

45-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/226-create-container-options/Program.cs" id="create_container" highlight="2":::
45+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/226-create-container-options/Program.cs" id="create_container" highlight="2":::
4646

4747
The [``Database.CreateContainerAsync``](/dotnet/api/microsoft.azure.cosmos.database.createcontainerasync) method will throw an exception if a database with the same name already exists.
4848

4949
### Create a container asynchronously if it doesn't already exist
5050

5151
The following example creates a container asynchronously only if it doesn't already exist on the account:
5252

53-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/226-create-container-options/Program.cs" id="create_container_check" highlight="2":::
53+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/226-create-container-options/Program.cs" id="create_container_check" highlight="2":::
5454

5555
The [``Database.CreateContainerIfNotExistsAsync``](/dotnet/api/microsoft.azure.cosmos.database.createcontainerifnotexistsasync) method will only create a new container if it doesn't already exist. This method is useful for avoiding errors if you run the same code multiple times.
5656

@@ -60,7 +60,7 @@ In all examples so far, the response from the asynchronous request was cast imme
6060

6161
The following example shows the **Database.CreateContainerIfNotExistsAsync** method returning a **ContainerResponse**. Once returned, you can parse response properties and then eventually get the underlying **Container** object:
6262

63-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/226-create-container-options/Program.cs" id="create_container_response" highlight="2,6":::
63+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/226-create-container-options/Program.cs" id="create_container_response" highlight="2,6":::
6464

6565
## Next steps
6666

articles/cosmos-db/nosql/how-to-dotnet-create-database.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ To create a database, call one of the following methods:
4242

4343
The following example creates a database asynchronously:
4444

45-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/201-create-database-options/Program.cs" id="create_database" highlight="2":::
45+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/201-create-database-options/Program.cs" id="create_database" highlight="2":::
4646

4747
The [``CosmosClient.CreateDatabaseAsync``](/dotnet/api/microsoft.azure.cosmos.cosmosclient.createdatabaseasync) method will throw an exception if a database with the same name already exists.
4848

4949
### Create a database asynchronously if it doesn't already exist
5050

5151
The following example creates a database asynchronously only if it doesn't already exist on the account:
5252

53-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/201-create-database-options/Program.cs" id="create_database_check" highlight="2":::
53+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/201-create-database-options/Program.cs" id="create_database_check" highlight="2":::
5454

5555
The [``CosmosClient.CreateDatabaseIfNotExistsAsync``](/dotnet/api/microsoft.azure.cosmos.cosmosclient.createdatabaseifnotexistsasync) method will only create a new database if it doesn't already exist. This method is useful for avoiding errors if you run the same code multiple times.
5656

@@ -60,7 +60,7 @@ In all examples so far, the response from the asynchronous request was cast imme
6060

6161
The following example shows the **CosmosClient.CreateDatabaseIfNotExistsAsync** method returning a **DatabaseResponse**. Once returned, you can parse response properties and then eventually get the underlying **Database** object:
6262

63-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/201-create-database-options/Program.cs" id="create_database_response" highlight="2,6":::
63+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/201-create-database-options/Program.cs" id="create_database_response" highlight="2,6":::
6464

6565
## Next steps
6666

articles/cosmos-db/nosql/how-to-dotnet-create-item.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ When referencing the item using a URI, use the system-generated *resource identi
4343
> [!NOTE]
4444
> The examples in this article assume that you have already defined a C# type to represent your data named **Product**:
4545
>
46-
> :::code language="csharp" source="~/azure-cosmos-dotnet-v3/250-create-item/Product.cs" id="type" :::
46+
> :::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/250-create-item/Product.cs" id="type" :::
4747
>
4848
> The examples also assume that you have already created a new object of type **Product** named **newItem**:
4949
>
50-
> :::code language="csharp" source="~/azure-cosmos-dotnet-v3/250-create-item/Program.cs" id="create_object" :::
50+
> :::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/250-create-item/Program.cs" id="create_object" :::
5151
>
5252
5353
To create an item, call one of the following methods:
@@ -60,23 +60,23 @@ To create an item, call one of the following methods:
6060

6161
The following example creates a new item asynchronously:
6262

63-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/250-create-item/Program.cs" id="create_item" :::
63+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/250-create-item/Program.cs" id="create_item" :::
6464

6565
The [``Container.CreateItemAsync<>``](/dotnet/api/microsoft.azure.cosmos.container.createitemasync) method will throw an exception if there's a conflict with the unique identifier of an existing item. To learn more about potential exceptions, see [``CreateItemAsync<>`` exceptions](/dotnet/api/microsoft.azure.cosmos.container.createitemasync#exceptions).
6666

6767
## Replace an item asynchronously
6868

6969
The following example replaces an existing item asynchronously:
7070

71-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/250-create-item/Program.cs" id="replace_item" :::
71+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/250-create-item/Program.cs" id="replace_item" :::
7272

7373
The [``Container.ReplaceItemAsync<>``](/dotnet/api/microsoft.azure.cosmos.container.replaceitemasync) method requires the provided string for the ``id`` parameter to match the unique identifier of the ``item`` parameter.
7474

7575
## Create or replace an item asynchronously
7676

7777
The following example will create a new item or replace an existing item if an item already exists with the same unique identifier:
7878

79-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/250-create-item/Program.cs" id="upsert_item" :::
79+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/250-create-item/Program.cs" id="upsert_item" :::
8080

8181
The [``Container.UpsertItemAsync<>``](/dotnet/api/microsoft.azure.cosmos.container.upsertitemasync) method will use the unique identifier of the ``item`` parameter to determine if there's a conflict with an existing item and to replace the item appropriately.
8282

articles/cosmos-db/nosql/how-to-dotnet-get-started.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export COSMOS_KEY="<cosmos-account-PRIMARY-KEY>"
197197

198198
Create a new instance of the **CosmosClient** class with the ``COSMOS_ENDPOINT`` and ``COSMOS_KEY`` environment variables as parameters.
199199

200-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/101-client-endpoint-key/Program.cs" id="endpoint_key" highlight="3-4":::
200+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/101-client-endpoint-key/Program.cs" id="endpoint_key" highlight="3-4":::
201201

202202
### Connect with a connection string
203203

@@ -295,7 +295,7 @@ export COSMOS_CONNECTION_STRING="<cosmos-account-PRIMARY-CONNECTION-STRING>"
295295

296296
Create a new instance of the **CosmosClient** class with the ``COSMOS_CONNECTION_STRING`` environment variable as the only parameter.
297297

298-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/102-client-connection-string/Program.cs" id="connection_string" highlight="3":::
298+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/102-client-connection-string/Program.cs" id="connection_string" highlight="3":::
299299

300300
### Connect using the Microsoft Identity Platform
301301

@@ -325,33 +325,33 @@ dotnet build
325325

326326
In your code editor, add using directives for ``Azure.Core`` and ``Azure.Identity`` namespaces.
327327

328-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/103-client-default-credential/Program.cs" id="using_identity_directives":::
328+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/103-client-default-credential/Program.cs" id="using_identity_directives":::
329329

330330
#### Create CosmosClient with default credential implementation
331331

332332
If you're testing on a local machine, or your application will run on Azure services with direct support for managed identities, obtain an OAuth token by creating a [``DefaultAzureCredential``](/dotnet/api/azure.identity.defaultazurecredential) instance.
333333

334334
For this example, we saved the instance in a variable of type [``TokenCredential``](/dotnet/api/azure.core.tokencredential) as that's a more generic type that's reusable across SDKs.
335335

336-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/103-client-default-credential/Program.cs" id="credential":::
336+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/103-client-default-credential/Program.cs" id="credential":::
337337

338338
Create a new instance of the **CosmosClient** class with the ``COSMOS_ENDPOINT`` environment variable and the **TokenCredential** object as parameters.
339339

340-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/103-client-default-credential/Program.cs" id="default_credential" highlight="4":::
340+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/103-client-default-credential/Program.cs" id="default_credential" highlight="4":::
341341

342342
#### Create CosmosClient with a custom credential implementation
343343

344344
If you plan to deploy the application out of Azure, you can obtain an OAuth token by using other classes in the [Azure.Identity client library for .NET](/dotnet/api/overview/azure/identity-readme). These other classes also derive from the ``TokenCredential`` class.
345345

346346
For this example, we create a [``ClientSecretCredential``](/dotnet/api/azure.identity.clientsecretcredential) instance by using client and tenant identifiers, along with a client secret.
347347

348-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/104-client-secret-credential/Program.cs" id="credential" highlight="3-5":::
348+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/104-client-secret-credential/Program.cs" id="credential" highlight="3-5":::
349349

350350
You can obtain the client ID, tenant ID, and client secret when you register an application in Azure Active Directory (AD). For more information about registering Azure AD applications, see [Register an application with the Microsoft identity platform](../../active-directory/develop/quickstart-register-app.md).
351351

352352
Create a new instance of the **CosmosClient** class with the ``COSMOS_ENDPOINT`` environment variable and the **TokenCredential** object as parameters.
353353

354-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/104-client-secret-credential/Program.cs" id="secret_credential" highlight="4":::
354+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/104-client-secret-credential/Program.cs" id="secret_credential" highlight="4":::
355355

356356
## Build your application
357357

articles/cosmos-db/nosql/how-to-dotnet-query-items.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ To learn more about the SQL syntax for Azure Cosmos DB for NoSQL, see [Getting s
3838
> [!NOTE]
3939
> The examples in this article assume that you have already defined a C# type to represent your data named **Product**:
4040
>
41-
> :::code language="csharp" source="~/azure-cosmos-dotnet-v3/300-query-items/Product.cs" id="type" :::
41+
> :::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/300-query-items/Product.cs" id="type" :::
4242
>
4343
4444
To query items in a container, call one of the following methods:
@@ -50,13 +50,13 @@ To query items in a container, call one of the following methods:
5050

5151
This example builds a SQL query using a simple string, retrieves a feed iterator, and then uses nested loops to iterate over results. The outer **while** loop will iterate through result pages, while the inner **foreach** loop iterates over results within a page.
5252

53-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/300-query-items/Program.cs" id="query_items_sql" :::
53+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/300-query-items/Program.cs" id="query_items_sql" :::
5454

5555
The [Container.GetItemQueryIterator<>](/dotnet/api/microsoft.azure.cosmos.container.getitemqueryiterator) method returns a [``FeedIterator<>``](/dotnet/api/microsoft.azure.cosmos.feediterator-1) that is used to iterate through multi-page results. The ``HasMoreResults`` property indicates if there are more result pages left. The ``ReadNextAsync`` method gets the next page of results as an enumerable that is then used in a loop to iterate over results.
5656

5757
Alternatively, use the [QueryDefinition](/dotnet/api/microsoft.azure.cosmos.querydefinition) to build a SQL query with parameterized input:
5858

59-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/300-query-items/Program.cs" id="query_items_sql_parameters" :::
59+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/300-query-items/Program.cs" id="query_items_sql_parameters" :::
6060

6161
> [!TIP]
6262
> Parameterized input values can help prevent many common SQL query injection attacks.
@@ -65,7 +65,7 @@ Alternatively, use the [QueryDefinition](/dotnet/api/microsoft.azure.cosmos.quer
6565

6666
In this example, an [``IQueryable``<>](/dotnet/api/system.linq.iqueryable) object is used to construct a [Language Integrated Query (LINQ)](/dotnet/csharp/programming-guide/concepts/linq/). The results are then iterated over using a feed iterator.
6767

68-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/300-query-items/Program.cs" id="query_items_queryable" :::
68+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/300-query-items/Program.cs" id="query_items_queryable" :::
6969

7070
The [Container.GetItemLinqQueryable<>](/dotnet/api/microsoft.azure.cosmos.container.getitemlinqqueryable) method constructs an ``IQueryable`` to build the LINQ query. Then the ``ToFeedIterator<>`` method is used to convert the LINQ query expression into a [``FeedIterator<>``](/dotnet/api/microsoft.azure.cosmos.feediterator-1).
7171

articles/cosmos-db/nosql/how-to-dotnet-read-item.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Every item in Azure Cosmos DB for NoSQL has a unique identifier specified by the
2626
> [!NOTE]
2727
> The examples in this article assume that you have already defined a C# type to represent your data named **Product**:
2828
>
29-
> :::code language="csharp" source="~/azure-cosmos-dotnet-v3/275-read-item/Product.cs" id="type" :::
29+
> :::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/275-read-item/Product.cs" id="type" :::
3030
>
3131
3232
To perform a point read of an item, call one of the following methods:
@@ -39,19 +39,19 @@ To perform a point read of an item, call one of the following methods:
3939

4040
The following example point reads a single item asynchronously and returns a deserialized item using the provided generic type:
4141

42-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/275-read-item/Program.cs" id="read_item" :::
42+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/275-read-item/Program.cs" id="read_item" :::
4343

4444
The [``Database.ReadItemAsync<>``](/dotnet/api/microsoft.azure.cosmos.container.readitemasync) method reads and item and returns an object of type [``ItemResponse<>``](/dotnet/api/microsoft.azure.cosmos.itemresponse-1). The **ItemResponse<>** type inherits from the [``Response<>``](/dotnet/api/microsoft.azure.cosmos.response-1) type, which contains an implicit conversion operator to convert the object into the generic type. To learn more about implicit operators, see [user-defined conversion operators](/dotnet/csharp/language-reference/operators/user-defined-conversion-operators).
4545

4646
Alternatively, you can return the **ItemResponse<>** generic type and explicitly get the resource. The more general **ItemResponse<>** type also contains useful metadata about the underlying API operation. In this example, metadata about the request unit charge for this operation is gathered using the **RequestCharge** property.
4747

48-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/275-read-item/Program.cs" id="read_item_expanded" :::
48+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/275-read-item/Program.cs" id="read_item_expanded" :::
4949

5050
## Read an item as a stream asynchronously
5151

5252
This example reads an item as a data stream directly:
5353

54-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/275-read-item/Program.cs" id="read_item_stream" :::
54+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/275-read-item/Program.cs" id="read_item_stream" :::
5555

5656
The [``Container.ReadItemStreamAsync``](/dotnet/api/microsoft.azure.cosmos.container.readitemstreamasync) method returns the item as a [``Stream``](/dotnet/api/system.io.stream) without deserializing the contents.
5757

@@ -61,7 +61,7 @@ If you aren't planning to deserialize the items directly, using the stream APIs
6161

6262
In this example, a list of tuples containing unique identifier and partition key pairs are used to look up and retrieve multiple items:
6363

64-
:::code language="csharp" source="~/azure-cosmos-dotnet-v3/275-read-item/Program.cs" id="read_multiple_items" :::
64+
:::code language="csharp" source="~/cosmos-db-nosql-dotnet-samples/275-read-item/Program.cs" id="read_multiple_items" :::
6565

6666
[``Container.ReadManyItemsAsync<>``](/dotnet/api/microsoft.azure.cosmos.container.readmanyitemsasync) returns a list of items based on the unique identifiers and partition keys you provide. This operation is typically more performant than a query since you'll effectively perform a point read operation on all items in the list.
6767

0 commit comments

Comments
 (0)