gpt4 book ai didi

c# - 使用 C# SDK 从 CosmosDb 中删除文档

转载 作者:行者123 更新时间:2023-12-02 03:19:06 25 4
gpt4 key购买 nike

我尝试使用下面的代码从 CosmosDB 中删除文档,但每次都会收到以下错误:“Microsoft.Azure.Documents.DocumentClientException:系统中不存在具有指定 ID 的实体”

该文档肯定在数据库中: enter image description here

这是我正在使用的代码:

    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") });

有人知道问题可能是什么吗?

谢谢

最佳答案

PartitionKey属性(property)在RequestOptions class 代表值而不是分区键的定义。

这意味着您删除的行应该是这样的:

var result = await this.client.DeleteDocumentAsync(docUri, new RequestOptions { PartitionKey = new PartitionKey(documentId) });

关于c# - 使用 C# SDK 从 CosmosDb 中删除文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55341814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com