【发布时间】:2018-01-17 10:26:33
【问题描述】:
我在 azure cosmos db 中使用分区集合。 我将文档插入集合中。我正在尝试使用以下代码删除文档,但它没有被删除。抛出以下异常。
internal static bool DeleteDocumentUnderPartition(AzureDocumentDbCollectionKind collectionKind, string partitionKey, string id)
{
var doc = DocumentClient.CreateDocumentQuery(GetCollectionLink(collectionKind), new FeedOptions
{
PartitionKey = new PartitionKey(partitionKey)
}).AsEnumerable().FirstOrDefault(x => x.Id.Equals(id));
DocumentClient.DeleteDocumentAsync(doc.SelfLink);
return true;
}
传递的 partitionKey 的值:“4c1429ca58f84e86a3f2e3d9ba1b74de”
传递的 id 值:“aa20ea966258492792864c3817313b2a”
异常 -->
DocumentClientException:消息:{“错误”:[“找不到资源”]} ActivityId:96696cde-3ea3-41fb-bc9c-70dfd8cfac36,请求 URI: /apps/9dee6cc4-be09-426e-b153-f213b908337a/services/e61dcc20-86c2-4751-b4b7-53fd686d04ae/partitions/42db755a-bded-4fe9-bd4c-3561fae0aaa9/replicas/131599878492s 请求统计:
响应时间:2018-01-18T10:20:07.5146574Z,StoreReadResult: 存储物理地址: rntbd://100.114.47.168:13700 /应用/ 9dee6cc4-be09-426e-B153-f213b908337a /服务/ e61dcc20-86c2-4751-b4b7-53fd686d04ae /分区/ 42db755a-bded-4fe9-bd4c-3561fae0aaa9 /复制/ 131599878429038582s, LSN:177530,GlobalCommittedLsn:177530,PartitionKeyRangeId:, IsValid:True,StatusCode:0,IsGone:False,IsNotFound:True, RequestCharge:1,ItemLSN:-1,ResourceType:集合, 操作类型:读取
响应时间:2018-01-18T10:20:07.5146574Z,StoreReadResult: 存储物理地址: rntbd://100.114.45.40:13700 /应用/ 9dee6cc4-be09-426e-B153-f213b908337a /服务/ e61dcc20-86c2-4751-b4b7-53fd686d04ae /分区/ 42db755a-bded-4fe9-bd4c-3561fae0aaa9 /复制/ 131606373510679694s, LSN:177530,GlobalCommittedLsn:177530,PartitionKeyRangeId:, IsValid:True,StatusCode:0,IsGone:False,IsNotFound:True, RequestCharge:1,ItemLSN:-1,ResourceType:集合, 操作类型:读取
但是,从另一个集合(非分区集合)中删除文档对我有用。 任何帮助将不胜感激。
【问题讨论】:
-
你确定
Database.Id和collectionKind.ToString()对应一个数据库和集合? -
@juunas,是的!我能够从同一个分区集合中检索文档。
-
您为
partitionKey传递的值是多少? -
@GauravMantri 这是一个字符串值(一些 guid 值)映射到创建集合时配置的分区键
标签: c# azure azure-cosmosdb