2
votes

I created a document db database with RU shared at DB level rather than at container level. Is it possible to create a collection without partition under the same DB? When I try to do the same with the code below I get an error

Provisioned throughput collection should have a partition key

private async Task CreatePartitionLessCollection()
{
    try
    {
        DocumentClient documentClient = new DocumentClient(new Uri(EndpointUrl), PrimaryKey);
        DocumentCollection myCollection = new DocumentCollection();
        myCollection.Id = "MyCollection";
        await documentClient.CreateDocumentCollectionAsync(
                UriFactory.CreateDatabaseUri("MyDB"), myCollection, new RequestOptions { OfferThroughput = 400 });
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.GetBaseException().Message);
    }
 }
1

1 Answers

0
votes

Reproduce your issue on my side,it indicates that we can't create provisioned throughput collection without partition key. Because the throughput setting at the db level will be shared across all the inside collections :

enter image description here

Please see this document to know the choice about setting db level or container level throughput.If you want to create a few partitioned collections and a few non-partitioned collections,you could try to set it at collection level.

Some key statements:

Provisioning throughput for individual containers will guarantee the reservation of throughput for that specific Cosmos DB container (i.e., a table or a collection or a graph) backed by the throughput SLA for that container. This allows you to have a fine-grained control over the throughput you want for a container at any given point in time. On the other hand, provisioning throughput on a Cosmos DB database, allows you to share the throughput among all the containers that belong to that database. This allows you to pool the provisioned throughput across a set of containers within a Cosmos DB database.