I'm using a partitioned collection in azure cosmos db. I inserted documents into the collection. I'm trying to delete a document using the following code, but it is not getting deleted. Throws the following exception.
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;
}
Value for partitionKey passed: "4c1429ca58f84e86a3f2e3d9ba1b74de"
Value for id passed: "aa20ea966258492792864c3817313b2a"
Exception -->
DocumentClientException: Message: {"Errors":["Resource Not Found"]} ActivityId: 96696cde-3ea3-41fb-bc9c-70dfd8cfac36, Request 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/partitions/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
However, deleting a document from another collection (non-partitioned collection) works for me. Any help would be greatly appreciated.
Database.Id
andcollectionKind.ToString()
correspond to a database and collection? – juunaspartitionKey
? – Gaurav Mantri