DeleteDocumentAsync – PartitionKey value must be supplied

I was trying to delete a document in DocumentDB / CosmoDB and I was surprised to be faced with the error message of, ‘PartitionKey value must be supplied’. There doesn’t appear to be a way of passing the partition key to DeleteDocumentAsync. The trick is to use the request options. For example, if your collection is partitioned by ProductID;

await this.documentClient.DeleteDocumentAsync(productDocument._self, new RequestOptions { PartitionKey = new Microsoft.Azure.Documents.PartitionKey(productDocument.ProductID) });

2 thoughts on “DeleteDocumentAsync – PartitionKey value must be supplied

  1. JohnDoe October 8, 2019 / 9:20 am

    my event has no partition key, so i’m stuck here and can’t delete it. I don’t understand their logic all the information in selflink is already provided to remove the document…. And RequestOptions doesn’t accept null partition key

  2. patelriki13 November 3, 2022 / 3:33 am

    Can you please try Microsoft.Azure.Documents.PartitionKey.None in your case.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s