这可能是一个非常简单和愚蠢的错误,但我不确定这是如何失败的。我使用了https://github.com/Azure/azure-cosmos-python#insert-data教程。如何查询数据库,然后使用这些ids
进行删除,然后它们就不存在了
周末到来之前有人能帮忙吗?谢谢,努力想知道这是怎么失败的
错误:
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"}
这是我的密码
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)```
问题很可能是文档的
id
和PartitionKey
值不匹配。文档在集合中通过其id和PartitionKey值的组合进行唯一标识因此,为了删除文档,您需要为文档的id及其PartitionKey值指定正确的值
在对
client.DeleteItem()
的调用中指定分区键时,您选择了:DeleteItem()
的额外参数应该指定分区键的值根据您的注释,
/class
是您的分区键。所以我相信,如果你把参数改成:希望这能奏效
相关问题 更多 >
编程相关推荐