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?
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With