[英]Deleting document from CosmosDb using c# SDK
我正在嘗試使用下面的代碼從 CosmosDB 中刪除一個文檔,但每次都會出現以下錯誤:“Microsoft.Azure.Documents.DocumentClientException:系統中不存在具有指定 ID 的實體”
這是我正在使用的代碼:
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") });
任何人都知道這個問題可能是什么?
謝謝
RequestOptions
類中的PartitionKey
屬性表示值而不是分區鍵的定義。
這意味着您的刪除行應該是這樣的:
var result = await this.client.DeleteDocumentAsync(docUri, new RequestOptions { PartitionKey = new PartitionKey(documentId) });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.