简体   繁体   中英

I am not able to delete document from azure Cosmos DB database

I am learning micorosoft azure and facing this issue. My Document is :

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

My Code is:

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;

Every time i get the same error: One or more errors occurred. (Response status code does not indicate success: NotFound (404); Substatus: 0; ActivityId: f40e6c70-589a-43d3-a329-aa4564fcc630; Reason: ({ "Errors": [ "Resource Not Found. Learn more: https://aka.ms/cosmosdb-tsg-not-found"]});)

The error is not clear.Please help me to find the solution

你的代码是对的,我这边删除成功了。请检查你的conatinerName是否和你在azure Portal上的一样。id,partition key value等其他东西也会导致这个错误,请确保它们是正确的。(它们是在您的代码中正确,如果您提供的文件是正确的)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM