Azure Cosmos DB,删除 IDS(肯定存在)

2024-06-28

这可能是一个非常简单和愚蠢的错误,但我不确定这是如何失败的。我已经用过https://github.com/Azure/azure-cosmos-python#insert-data https://github.com/Azure/azure-cosmos-python#insert-data教程。我如何查询数据库然后使用它们ids删除然后它们就不存在了。

周末到来之前有人能帮忙吗?谢谢,努力看看这是如何失败的!

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"}

这是我的代码...

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)```

在调用中指定分区键时client.DeleteItem(),您选择了:

{'partitionKey': 'class'}

额外的参数DeleteItem()应该指定value您的分区键。

根据您的评论,/class是你的分区键。所以我相信,如果你将参数更改为:

{'partitionKey': 'value-of-partition-key'}

这应该会起作用。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Azure Cosmos DB,删除 IDS(肯定存在) 的相关文章

随机推荐