Azure Cosmos DB,删除IDS(肯定存在) [英] Azure Cosmos DB, Delete IDS (definitely exist)

查看:95
本文介绍了Azure Cosmos DB,删除IDS(肯定存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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!

错误:

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()的调用中指定分区键时,您选择了:

When specifying the partition key in the call to client.DeleteItem(), you chose:

{'partitionKey': 'class'}

DeleteItem()的额外参数应指定分区键的.

The extra parameter to DeleteItem() should be specifying the value of your partition key.

根据您的评论,/class 是您的分区键.因此,我相信,如果您将参数更改为:

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

这应该可以正常工作.

这篇关于Azure Cosmos DB,删除IDS(肯定存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆