d199224
d199224

Reputation: 541

Deleting document from CosmosDb using c# SDK

I am trying to delete a document from CosmosDB using the code below but each time Keep getting the following error: "Microsoft.Azure.Documents.DocumentClientException: Entity with the specified id does not exist in the system"

The document is definitely in the database: enter image description here

This is the code I'm using:

    this.client = new DocumentClient(new Uri(EndpointUri), PrimaryKey);
    var docUri = UriFactory.CreateDocumentUri(DatabaseName, CollectionName, documentId);

    var result = await this.client.DeleteDocumentAsync(docUri, new RequestOptions { PartitionKey = new PartitionKey("/id") });

Anyone any idea on what the issue may be?

Thanks

Upvotes: 2

Views: 2108

Answers (1)

Nick Chapsas
Nick Chapsas

Reputation: 7200

The PartitionKey property in the RequestOptions class represents the value not the definition of the partition key.

This means that yous delete line should be this:

var result = await this.client.DeleteDocumentAsync(docUri, new RequestOptions { PartitionKey = new PartitionKey(documentId) });

Upvotes: 5

Related Questions