4

DeleteDocumentAsync and ReadDocumentAsync don't work for me when I have a partitioned collection. I used the RequestOptions:

await client.DeleteDocumentAsync(document.SelfLink, new RequestOptions { 
    PartitionKey = new PartitionKey("mykey")
}).ConfigureAwait(false); // This works.

var uri = UriFactory.CreateDocumentUri("db", "coll", "id1");

await client.DeleteDocumentAsync(uri, new RequestOptions { 
    PartitionKey = new PartitionKey("mykey")
}).ConfigureAwait(false); // This throws

Partition key provided either doesn't correspond to definition in the collection or doesn't match partition key field values specified in the document.

Any ideas?

8
  • Is myKey in new PartitionKey("mykey") the name of the PartitionKey attribute (e.g. lastName) or the value of the attribute (e.g. Smith)? Commented Feb 3, 2018 at 3:09
  • Thanks for the help, but why will it succeed with the SelfLink with the wrong value? Commented Feb 5, 2018 at 21:59
  • @Jose I can't delete documents with selfLink or uri if i set the wrong value the partition key.Would you please post your sample data structure? BTW, the class should be the RequestOptions not RequestOption in your code. Commented Feb 6, 2018 at 7:25
  • @Jose Hi,any progress?Does my answer helps you? Commented Feb 8, 2018 at 1:42
  • Sorry @Jay, I've been busy somewhere else. I'll try soon to rewrite a simple sample outside our code-base, which was written by somebody else. Commented Feb 9, 2018 at 15:46

1 Answer 1

4

I tried the your snippet of code which throws exception, it works for me.

I think you misunderstand the meaning of partitionkey property in the RequestOptions.

For example , my container is created like this:

enter image description here

The partition key is "name" for my collection here. You could check your collection's partition key.

And my documents as below :

{
    "id": "1",
    "name": "jay"
}

{
    "id": "2",
    "name": "jay2"
}

My partitionkey is 'name', so here I have two paritions : 'jay' and 'jay1'.

So, here you should set the partitionkey property to 'jay' or 'jay2',not 'name'.

var uri = UriFactory.CreateDocumentUri("db", "part", "1");

client.DeleteDocumentAsync(uri, new RequestOptions
{
    PartitionKey = new PartitionKey("jay")
}).ConfigureAwait(false); 

Hope it helps you.

Sign up to request clarification or add additional context in comments.

1 Comment

I can't see the definition of the partition key in the screenshot where you created the container. Could you explain that part please? Because here I am having difficulties - I know how to pass the key later in CRUD operations, but seem to have something wrong on creation of the collection. How do you specify which is the partition key?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.