<legend id='DJq5b'><style id='DJq5b'><dir id='DJq5b'><q id='DJq5b'></q></dir></style></legend>

  • <i id='DJq5b'><tr id='DJq5b'><dt id='DJq5b'><q id='DJq5b'><span id='DJq5b'><b id='DJq5b'><form id='DJq5b'><ins id='DJq5b'></ins><ul id='DJq5b'></ul><sub id='DJq5b'></sub></form><legend id='DJq5b'></legend><bdo id='DJq5b'><pre id='DJq5b'><center id='DJq5b'></center></pre></bdo></b><th id='DJq5b'></th></span></q></dt></tr></i><div id='DJq5b'><tfoot id='DJq5b'></tfoot><dl id='DJq5b'><fieldset id='DJq5b'></fieldset></dl></div>

      <bdo id='DJq5b'></bdo><ul id='DJq5b'></ul>

    <small id='DJq5b'></small><noframes id='DJq5b'>

      1. <tfoot id='DJq5b'></tfoot>
      2. 无法从 CosmosDB 中删除项目

        Cannot delete item from CosmosDB(无法从 CosmosDB 中删除项目)
      3. <small id='QBthS'></small><noframes id='QBthS'>

        <legend id='QBthS'><style id='QBthS'><dir id='QBthS'><q id='QBthS'></q></dir></style></legend>

            <i id='QBthS'><tr id='QBthS'><dt id='QBthS'><q id='QBthS'><span id='QBthS'><b id='QBthS'><form id='QBthS'><ins id='QBthS'></ins><ul id='QBthS'></ul><sub id='QBthS'></sub></form><legend id='QBthS'></legend><bdo id='QBthS'><pre id='QBthS'><center id='QBthS'></center></pre></bdo></b><th id='QBthS'></th></span></q></dt></tr></i><div id='QBthS'><tfoot id='QBthS'></tfoot><dl id='QBthS'><fieldset id='QBthS'></fieldset></dl></div>
            <tfoot id='QBthS'></tfoot>

                  <bdo id='QBthS'></bdo><ul id='QBthS'></ul>
                    <tbody id='QBthS'></tbody>

                  本文介绍了无法从 CosmosDB 中删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Azure Functions httpTrigger 调用从我的数据库中删除一个项目.

                  I am trying to use an Azure Functions httpTrigger call to delete an item from my database.

                  import { CosmosClient,  } from '@azure/cosmos'
                  
                  const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
                      const client = new CosmosClient(process.env.cosmosDB)
                      const database = client.database('testDB');
                      const container = database.container('workers');
                      const item = container.item('28a31558-ff8c-40c3-a7e8-1e8904c5ff72', '/id')
                      console.log(await item.delete())
                  }
                  

                  我什至尝试将值硬编码到代码中(如您所见),但我总是会收到 404 not found 错误:

                  I even tried to hardcode the values into the code (as you can see) but I will always get 404 not found error:

                  Executed 'Functions.worker-delete' (Failed, Id=81ab43cf-a223-48af-89e1-a15676346ef0)
                  System.Private.CoreLib: Exception while executing function: Functions.worker-delete. System.Private.CoreLib: Result: Failure
                  Exception: Error: Entity with the specified id does not exist in the system., 
                  RequestStartTime: 2020-05-11T12:30:44.4010890Z, RequestEndTime: 2020-05-11T12:30:44.4010890Z,  Number of regions attempted:1
                  ResponseTime: 2020-05-11T12:30:44.4010890Z, StoreResult: StorePhysicalAddress: xxx, LSN: 769914, GlobalCommittedLsn: 769914, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 404, SubStatusCode: 0, RequestCharge: 1.24, ItemLSN: -1, SessionToken: -1#769914, UsingLocalLSN: False, TransportException: null, ResourceType: Document, OperationType: Delete
                  , Microsoft.Azure.Documents.Common/2.10.0
                  Stack: Error: Entity with the specified id does not exist in the system., 
                  RequestStartTime: 2020-05-11T12:30:44.4010890Z, RequestEndTime: 2020-05-11T12:30:44.4010890Z,  Number of regions attempted:1
                  ResponseTime: 2020-05-11T12:30:44.4010890Z, StoreResult: StorePhysicalAddress: xxx, LSN: 769914, GlobalCommittedLsn: 769914, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 404, SubStatusCode: 0, RequestCharge: 1.24, ItemLSN: -1, SessionToken: -1#769914, UsingLocalLSN: False, TransportException: null, ResourceType: Document, OperationType: Delete
                  , Microsoft.Azure.Documents.Common/2.10.0
                      at xxx/node_modules/@azure/cosmos/dist/index.js:6973:39
                      at Generator.next (<anonymous>)
                      at fulfilled (xxx/node_modules/tslib/tslib.js:110:62)
                      at process._tickCallback (internal/process/next_tick.js:68:7).
                  

                  我检查了三次:

                  • 连接字符串
                  • 数据库名称
                  • 容器名称
                  • 项目 ID
                  • 分区

                  推荐答案

                  通过container.item()获取文档时,两个参数分别为:

                  When retrieving a document via container.item(), the two parameters are:

                  • 文档编号
                  • 分区键

                  第二个参数(分区键)需要是分区键的.在您的示例中,您使用的是分区键的 path,因此它正在检查/id"的分区键值:

                  The 2nd parameter (partition key) needs to be the value of the partition key. In your example, you had the path to the partition key instead, so it's checking for a partition key value of "/id":

                  const item = container.item('28a31558-ff8c-40c3-a7e8-1e8904c5ff72', '/id')
                  

                  这需要改成:

                  const item = container.item('28a31558-ff8c-40c3-a7e8-1e8904c5ff72', '<partition-key-value')
                  

                  这篇关于无法从 CosmosDB 中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  quot;Status Code:200 OK (from ServiceWorker)quot; in Chrome Network DevTools?(“状态码:200 OK(来自 ServiceWorker)在 Chrome 网络开发工具中?)
                  How to set a header for a HTTP GET request, and trigger file download?(如何为 HTTP GET 请求设置标头并触发文件下载?)
                  Adding custom HTTP headers using JavaScript(使用 JavaScript 添加自定义 HTTP 标头)
                  SQL Query DocumentDB in Azure Functions by an integer not working(通过整数在 Azure Functions 中 SQL 查询 DocumentDB 不起作用)
                  Azure Functions [JavaScript / Node.js] - HTTP call, good practices(Azure Functions [JavaScript/Node.js] - HTTP 调用,良好实践)
                  Azure Functions - Import Custom Node Module(Azure Functions - 导入自定义节点模块)

                  <small id='tyyQY'></small><noframes id='tyyQY'>

                  <i id='tyyQY'><tr id='tyyQY'><dt id='tyyQY'><q id='tyyQY'><span id='tyyQY'><b id='tyyQY'><form id='tyyQY'><ins id='tyyQY'></ins><ul id='tyyQY'></ul><sub id='tyyQY'></sub></form><legend id='tyyQY'></legend><bdo id='tyyQY'><pre id='tyyQY'><center id='tyyQY'></center></pre></bdo></b><th id='tyyQY'></th></span></q></dt></tr></i><div id='tyyQY'><tfoot id='tyyQY'></tfoot><dl id='tyyQY'><fieldset id='tyyQY'></fieldset></dl></div>
                        • <bdo id='tyyQY'></bdo><ul id='tyyQY'></ul>

                              <tbody id='tyyQY'></tbody>
                            <legend id='tyyQY'><style id='tyyQY'><dir id='tyyQY'><q id='tyyQY'></q></dir></style></legend>
                            <tfoot id='tyyQY'></tfoot>