Skip to content

Instantly share code, notes, and snippets.

View deborahc's full-sized avatar

Deborah Chen deborahc

  • Microsoft
View GitHub Profile
@deborahc
deborahc / CosmosTransactionalBatch.cs
Last active September 14, 2022 11:35
Do a transactional batch of operations against the same partition key value in Azure Cosmos DB .NET SDK
using Microsoft.Azure.Cosmos;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
// Use the transactional batch capability in .NET SDK V3.4 or higher
namespace CosmosBatchSample
{
class Program
@deborahc
deborahc / ScaleThroughput.cs
Last active August 1, 2019 00:39
Scale throughput of a container in Azure Cosmos DB .NET SDK V3 (GA)
// Scaling throughput (RU/s) using V3 SDK
static async Task ScaleThroughputDemo_SDKVersion3()
{
// Get reference to container
var container = cosmosClient.GetContainer(databaseId, containerId);
// Read value of current throughput (RU/s)
var currentThroughput = await container.ReadThroughputAsync();
var newThroughput = (int)currentThroughput * 2;
@deborahc
deborahc / CosmosBuilderPattern.cs
Last active September 14, 2022 11:34
Create a new CosmosClient and Container using the fluent builder pattern using the Azure Cosmos DB .NET SDK V3 (GA)
using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Cosmos.Fluent; // Use the new fluent namespace
using System.Threading.Tasks;
// Creating a new CosmosClient and Container using the fluent builder pattern
namespace CosmosDotnetSDKGetStarted
{
class Program
{
static async Task Main(string[] args)
@deborahc
deborahc / ScaleFixedContainer.cs
Last active August 1, 2019 04:57
Scaling a non-partitioned (fixed) container) with Azure Cosmos DB .NET V3 SDK (GA)
// Scale fixed container using partition key in .NET V3 SDK
public static async Task ScaleNonPartitionedContainer()
{
using (var cosmosClient = new CosmosClient(endpoint, key))
{
//Get reference to existing fixed container
var container = cosmosClient.GetDatabase(databaseId).GetContainer(containerId);
// Add item to container without partition key
var user = new User()
@deborahc
deborahc / CosmosGettingStarted.cs
Last active August 9, 2019 17:25
Getting started with Azure Cosmos DB .NET V3 SDK (GA)
using Microsoft.Azure.Cosmos;
using System;
using System.Threading.Tasks;
//Getting started with .NET SDK V3
namespace CosmosDotnetSDKGetStarted
{
class Program
{
static async Task Main(string[] args)
@deborahc
deborahc / CosmosStreamExample.cs
Last active November 10, 2023 20:36
Azure Cosmos DB .NET SDK Version 3 Stream API with query example
// Using the stream API to read data, in the context of an ASP.NET Web API
namespace CosmosWebAPI.Controllers
{
[Produces("application/json")]
[Route("api/ProductReview")]
// GET: api/ProductReview/productId/continuationToken
[HttpGet("{productId}/{continuationToken}", Name = "Get")]
// using the new stream api
public async Task<HttpResponseMessage> Query(string productId, string continuationToken)