问题
This is probably a very simple and silly mistake but I am unsure of how this is failing. I have used the https://github.com/Azure/azure-cosmos-python#insert-data tutorial. How can I query a database then used those ids
to delete and then they don't exist.
Can anyone help before the weekend sets in? Thanks, struggling to see how this fails!
Error:
azure.cosmos.errors.HTTPFailure: Status code: 404
{"code":"NotFound","message":"Entity with the specified id does not exist in the system., \r\nRequestStartTime: 2020-02-07T17:08:48.1413131Z,
RequestEndTime: 2020-02-07T17:08:48.1413131Z,
Number of regions attempted:1\r\nResponseTime: 2020-02-07T17:08:48.1413131Z,
StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-northeurope1-fd24.documents.azure.com:14363/apps/dedf1644-3129-4bd1-9eaa-8efc450341c4/services/956a2aa9-0cad-451f-a172-3f3c7d8353ef/partitions/bac75b40-384a-4019-a973-d2e85ada9c87/replicas/132248272332111641p/,
LSN: 79, GlobalCommittedLsn: 79, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 404,
SubStatusCode: 0, RequestCharge: 1.24, ItemLSN: -1, SessionToken: 0#79#13=-1,
UsingLocalLSN: False, TransportException: null, ResourceType: Document,
OperationType: Delete\r\n, Microsoft.Azure.Documents.Common/2.9.2"}
This is my code...
def get_images_to_check(database_id, container_id):
images = client.QueryItems("dbs/" + database_id + "/colls/" + container_id,
{
'query': 'SELECT * FROM c r WHERE r.manually_reviewed=@manrev',
'parameters': [
{'name': '@manrev', 'value': False}
]
},
{'enableCrossPartitionQuery': True})
return list(images)
def delete_data(database_id, container_id, data):
for item in data:
print(item['id'])
client.DeleteItem("dbs/" + database_id + "/colls/" + container_id + "/docs/" + item['id'], {'partitionKey': 'class'})
database_id = 'ModelData'
container_id = 'ImagePredictions'
container_id = 'IncorrectPredictions'
images_to_check = get_images_to_check(database_id, container_id)
delete_data(database_id, container_id, images_to_check)```
回答1:
When specifying the partition key in the call to client.DeleteItem()
, you chose:
{'partitionKey': 'class'}
The extra parameter to DeleteItem()
should be specifying the value of your partition key.
Per your comments, /class
is your partition key. So I believe that, if you change your parameter to something like:
{'partitionKey': 'value-of-partition-key'}
This should hopefully work.
回答2:
More than likely the issue is with mismatched id
and PartitionKey
value for the document. A document is uniquely identified in a collection by combination of it's id and PartitionKey value.
Thus in order to delete a document, you need to specify correct values for both the document's id and it's PartitionKey value.
来源:https://stackoverflow.com/questions/60118213/azure-cosmos-db-delete-ids-definitely-exist