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's avatar 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's avatar patelriki13 November 3, 2022 / 3:33 am

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

Leave a reply to patelriki13 Cancel reply