我在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 / 131599878429038582s,RequestStats:ResponseTime:2018-01-18T10:20:07.5146574Z,StoreReadResult:StorePhysicalAddress:rntbd://100.114.47.168 :13700 / apps / 9dee6cc4-be09-426e-b153-f213b908337a / services / e61dcc20-86c2-4751-b4b7-53fd686d04ae / partitions / 42db755a-bded-4fe9-bd4c-3561fae0aaa9 / replicas / 131599878429038582s,LSN:177530,GlobalCommittedLsn:177530 ,PartitionKeyRangeId :, IsValid:True,StatusCode:0,IsGone:False,IsNotFound:True,RequestCharge:1,ItemLSN:-1,ResourceType:Collection,OperationType:Read ResponseTime:2018-01-18T10:20:07.5146574Z,StoreReadResult :StorePhysicalAddress:rntbd://100.114.45.40:13700 / apps / 9dee6cc4-be09-426e-b153-f213b908337a / services / e61dcc20-86c2-4751-b4b7-53fd686d04ae / parti tions / 42db755a-bded-4fe9-bd4c-3561fae0aaa9 / replicas / 131606373510679694s,LSN:177530,GlobalCommittedLsn:177530,PartitionKeyRangeId :, IsValid:True,StatusCode:0,IsGone:False,IsNotFound:True,RequestCharge:1,ItemLSN: - 1,ResourceType:Collection,OperationType:Read
但是,从另一个集合(非分区集合)中删除文档对我有用 . 任何帮助将不胜感激 .
1 回答
我尝试使用示例代码重现您的问题,但是失败了 .
我在分区集合中的文件(id是我的分区键)就像:
我认为分区密钥可能是问题的关键 . 您需要提供分区键的值,而不是存储分区键的字段的名称 .
或者,如果可以正确删除文档,您可以尝试创建一个简单的新分区集合测试 .
希望它能帮到你 .
Update Answer:
我想你误解了
FeedOptions
中partitionkey
属性的含义 .例如,我的容器创建如下:
分区键是我的集合的“名称” . 您可以检查集合的分区键 .
我的文件如下:
我的
partitionkey
是 'name' ,所以我在这里有两个分区: 'jay' 和 'jay1' .所以,在这里你应该将
partitionkey
属性设置为'jay'或'jay2',而不是'name' .如果您没有设置错误的分区密钥,请分享您的分区密钥设置和要删除的文档的详细信息吗? (请隐藏敏感信息,谢谢)