【问题标题】:I am not able to delete document from azure Cosmos DB database我无法从 azure Cosmos DB 数据库中删除文档
【发布时间】:2020-09-03 23:32:26
【问题描述】:

我正在学习 micorosoft azure 并面临这个问题。 我的文件是:

{
    "customerid": 1,
    "customername": "Ron",
    "city": "NewYork",
    "id": "0c288834-fc7d-4f9d-95c7-722596e275c8"
}

我的代码是:

CosmosClient cosmosClient = new CosmosClient(endPoint, accountKey);
Database database = cosmosClient.GetDatabase(databaseName);
Container container = database.GetContainer(conatinerName);
PartitionKey pk = new PartitionKey("NewYork");
string id = "0c288834-fc7d-4f9d-95c7-722596e275c8";
ItemResponse<customer> t =container.DeleteItemAsync<customer>(id, pk).Result;

每次我得到同样的错误: 发生一个或多个错误。 (响应状态码不表示成功:NotFound(404);Substatus:0;ActivityId:f40e6c70-589a-43d3-a329-aa4564fcc630;原因:({ “错误”:[“找不到资源。了解更多:https://aka.ms/cosmosdb-tsg-not-found”]});)

错误不清楚。请帮我找到解决办法

【问题讨论】:

  • 错误很明显:在该分区键下找不到特定的 ID。尝试仅使用 ID 删除而不使用分区键。
  • 你的分区键是什么?好像不是“/city”。
  • 我的分区键是“城市”

标签: c# azure azure-cosmosdb azure-cosmosdb-sqlapi


【解决方案1】:

你的代码是对的。我这边删除成功。请检查你的conatinerName是否与你在azure门户上的相同。id,分区键值等其他内容也会导致此错误,请确保它们是正确的。 (如果您提供的文档正确,它们在您的代码中是正确的)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    相关资源
    最近更新 更多