Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception: Partition key provided ..., when using CreateDocumentUri with a partitioned document db

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?

like image 975
Jose Avatar asked Oct 18 '25 00:10

Jose


1 Answers

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.

like image 125
Jay Gong Avatar answered Oct 20 '25 15:10

Jay Gong