3
votes

I am having an issue deleting a document form document db. The code is very trivial and I am not doing anything fancy. Basically I am getting the self link of the document and then using the self link to delete but it is giving me exception.

await client.DeleteDocumentAsync(entity.SelfLink, new RequestOptions() { PartitionKey = new PartitionKey(partitionKey) }).ConfigureAwait(false);

entity is a newly added document which exists in database (I have checked its existence from Azure Portal)

The exception I am getting:

Message: {"Errors":["Resource Not Found"]} ActivityId: 052ad225-4e04-4757-89b8-51f6ccf55f7c, Request URI: https://sy3prdddc05-docdb-1.documents.azure.com:15236/apps/0ee0095b-872d-45bc-8739-67cfbd97db79/services/466a4dd1-27d3-45ca-b013-6875f06a38ab/partitions/73e5c3d8-0332-4c0c-9aec-47a3469ba958/replicas/131354346050636923p//dbs/l29HAA==/colls/l29HAKZFJwA=/docs/l29HAKZFJwAfAAAAAAAAAA==

Any idea??

2
Can you please ensure the partitionKey value matches with the value in the document you're trying to delete? - Gaurav Mantri
I just have one partition key in my database at the moment. I don't know what the issue is and could't find any help on net. - Poseidon
Whoever down-voted the question, could you please at least provide some feedback! - Poseidon

2 Answers

5
votes

I finally found the issue! The name of partition key I specified for collection was Pascal case not camel case! and apparently it is case sensitive so it couldn't find the partition key!

0
votes

I had a similar situation. In my Repository, I used a string as the partition key, in the document I used int type. Changed it to object to keep the Repository neutral and open for other types.

public virtual async Task DeleteAsync(string databaseId, string collectionId, string id, object partitionKey)
    {
        var reqOptions = new RequestOptions()
        {
            PartitionKey = new PartitionKey(partitionKey)
        };

        await Client.DeleteDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, id), reqOptions);
    }