3

There are some sample code that create collection in azure documentDB using Microsoft.Azure.DocumentDB. However, I could not find information about how to create the collection with different partition mode using c#.

From the portal, there are 2 modes: Single Partition and Partitioned.

Can we use one or another when create collection using Microsoft.Azure.DocumentDB?

1 Answer 1

7

You need to have the SDK Version 1.6.0 or newer to support Document DB Partitioning. Using the SDK you need to set the OfferThroughput value like shown below.

In this sample we set the /deviceId as the partition key.

DocumentClient client = new DocumentClient(new Uri(endpoint), authKey);
await client.CreateDatabaseAsync(new Database { Id = "db" });

// Collection for device telemetry. Here the JSON property deviceId will be used as the partition key to 
// spread across partitions. Configured for 10K RU/s throughput and an indexing policy that supports 
// sorting against any number or string property.
DocumentCollection myCollection = new DocumentCollection();
myCollection.Id = "coll";
myCollection.PartitionKey.Paths.Add("/deviceId");

await client.CreateDocumentCollectionAsync(
    UriFactory.CreateDatabaseUri("db"),
    myCollection,
    new RequestOptions { OfferThroughput = 20000 });

Note:

In order to create partitioned collections, you must specify a throughput value of > 10,000 request units per second. Since throughput is in multiples of 100, this has to be 10,100 or higher.

So when your OfferThroughput is set to less than 20000 then your collection will be Single Partition.

Sign up to request clarification or add additional context in comments.

1 Comment

Just a minor correction in Aram's response - I think you mean when throughput is set to less than 10000, then your collection has single partition. More details are available at github.com/Azure/azure-content/blob/master/articles/documentdb/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.