请帮助我理解我从 DELETE 方法中得到的这个错误

土沙

我正在尝试使用 DELETE 路由功能。我想要做的是获取idfromreq.params并使用它来删除与该特定id. 我在下面分享我的代码,这也是我得到的错误。有人可以告诉我为什么会出现此错误吗?我在这里使用 CosmosDb。

app.delete('/:id', async(req, res) => {

    try {
    
        const { id } = req.params;

        const dbResponse = await cosmosClient.databases.createIfNotExists({
            id: databaseId
        });


        let database = dbResponse.database;

        const { container } = await database.containers.createIfNotExists({id: containerId});

                    const docResponse = await container.item(id).delete();

        console.log("Item deleted");

        res.send(docResponse);
        
    } catch (error) {
        console.log(error);
        res.status(500).send("Error with database query: " + error.body);
    }

})

错误

{
  code: 400,
  body: '{"code":"BadRequest","message":"Message: {\\"Errors\\":[\\"The partition key supplied in x-ms-partitionkey header has fewer components than defined in the the collection.\\"]}\\r\\nActivityId: 2eefe53b-d025-4c50-b66d-6ff544ae1fd9, Request URI: /apps/d9dd667d-ffd4-45aa-ae65-801629672b13/services/7cabee75-7eb4-4732-8500-61a636907715/partitions/2bdc91e2-4247-4f18-a168-7efbb140f3e1/replicas/132642795034019191p, RequestStats: \\r\\nRequestStartTime: 2021-05-07T18:21:41.9351771Z, RequestEndTime: 2021-05-07T18:21:41.9351771Z,  Number of regions attempted:1\\r\\nResponseTime: 2021-05-07T18:21:41.9351771Z, StoreResult: StorePhysicalAddress: rntbd://10.0.0.131:14300/apps/d9dd667d-ffd4-45aa-ae65-801629672b13/services/7cabee75-7eb4-4732-8500-61a636907715/partitions/2bdc91e2-4247-4f18-a168-7efbb140f3e1/replicas/132642795034019191p, LSN: 78, GlobalCommittedLsn: 78, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 400, SubStatusCode: 1001, RequestCharge: 0, ItemLSN: -1, SessionToken: -1#78, UsingLocalLSN: False, TransportException: null, ResourceType: Document, OperationType: Delete\\r\\n, SDK: Microsoft.Azure.Documents.Common/2.11.0"}',
  headers: {
    'transfer-encoding': 'chunked',
    'content-type': 'application/json',
    'content-location': 'https://pod01-dev-cus-db-eastus.documents.azure.com/dbs/db/colls/partnership/docs/4040',
    server: 'Microsoft-HTTPAPI/2.0',
    'x-ms-activity-id': '2eefe53b-d025-4c50-b66d-6ff544ae1fd9',
    'x-ms-last-state-change-utc': 'Tue, 04 May 2021 21:27:07.912 GMT',
    'x-ms-schemaversion': '1.11',
    lsn: '78',
    'x-ms-request-charge': '0',
    'x-ms-quorum-acked-lsn': '78',
    'x-ms-substatus': '1001',
    'x-ms-current-write-quorum': '3',
    'x-ms-current-replica-set-size': '4',
    'x-ms-documentdb-partitionkeyrangeid': '0',
    'x-ms-xp-role': '1',
    'x-ms-global-committed-lsn': '78',
    'x-ms-number-of-read-regions': '0',
    'x-ms-transport-request-id': '9',
    'x-ms-cosmos-llsn': '78',
    'x-ms-cosmos-quorum-acked-llsn': '78',
    'x-ms-session-token': '0:-1#78',
    'x-ms-request-duration-ms': '0.216',
    'x-ms-serviceversion': 'version=2.11.0.0',
    'strict-transport-security': 'max-age=31536000',
    'x-ms-gatewayversion': 'version=2.11.0',
    date: 'Fri, 07 May 2021 18:21:41 GMT',
    'x-ms-throttle-retry-count': 0,
    'x-ms-throttle-retry-wait-time-ms': 0
  },
  activityId: '2eefe53b-d025-4c50-b66d-6ff544ae1fd9',
  substatus: 1001,
  requestHeaders: {
    'Cache-Control': 'no-cache',
    'x-ms-version': '2018-06-18',
    'x-ms-consistency-level': 'Session',
    'User-Agent': 'win32/10.0.19042 Nodejs/v14.16.1 azure-cosmos-js/2.1.7',
    'x-ms-date': 'Fri, 07 May 2021 18:21:41 GMT',
    Accept: 'application/json',
    authorization: 'type%3Dmaster%26ver%3D1.0%26sig%3D%2BMyYlVwpdgUWtXinv7F%2FoZVwcVglOfO%2FnS8hwW1sY4U%3D'
  }
}

我不知道什么是错误,邮递员也给了我一些不同的东西。

邮差错误

Error with database query: {"code":"BadRequest","message":"Message: {\"Errors\":[\"The partition key supplied in
x-ms-partitionkey header has fewer components than defined in the the collection.\"]}\r\nActivityId:
2eefe53b-d025-4c50-b66d-6ff544ae1fd9, Request URI:
/apps/d9dd667d-ffd4-45aa-ae65-801629672b13/services/7cabee75-7eb4-4732-8500-61a636907715/partitions/2bdc91e2-4247-4f18-a168-7efbb140f3e1/replicas/132642795034019191p,
RequestStats: \r\nRequestStartTime: 2021-05-07T18:21:41.9351771Z, RequestEndTime: 2021-05-07T18:21:41.9351771Z, Number
of regions attempted:1\r\nResponseTime: 2021-05-07T18:21:41.9351771Z, StoreResult: StorePhysicalAddress:
rntbd://10.0.0.131:14300/apps/d9dd667d-ffd4-45aa-ae65-801629672b13/services/7cabee75-7eb4-4732-8500-61a636907715/partitions/2bdc91e2-4247-4f18-a168-7efbb140f3e1/replicas/132642795034019191p,
LSN: 78, GlobalCommittedLsn: 78, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 400, SubStatusCode: 1001,
RequestCharge: 0, ItemLSN: -1, SessionToken: -1#78, UsingLocalLSN: False, TransportException: null, ResourceType:
Document, OperationType: Delete\r\n, SDK: Microsoft.Azure.Documents.Common/2.11.0"}
小王

您是否尝试使用以下代码?Azure官方示例在此。

const docResponse = await container.item(id, partitionKey).delete();

在此处输入图片说明

我在我身边测试,它奏效了。

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

请帮助我理解列表中的错误

请帮助我理解 Python 3 上的这个输出

请帮助我摆脱这个问题

请帮助我理解这个 PHP hack,我怎样才能绕过这个重新

请帮助我理解这个“包扩展不包含任何未扩展的参数包”编译器错误

请帮助我检查登录中的会话错误

请帮助我了解这个基本的C ++类实现

请帮助我纠正此细分错误

请帮助我找到错误-显示质数的程序

请帮助我VHDL编译错误

空指针异常错误。请帮助我

请帮助我解决此路线错误

请帮助我了解AVL树中的LR旋转

请帮助我在js按钮的onclick函数中

我不明白我的脚本中发生的错误,请帮助我

请任何人可以帮助我找出xml文件中的错误

Sql 加入查询错误。有人请帮助我

请帮助我在Bootstrap 3导航栏中找到错误

未捕获的参考错误:未定义绘图 - 请帮助我

请帮助我了解JRuby方法名称转换的不一致之处

我无法删除使用 react 创建的待办事项列表中的项目,请帮助我解决代码中的错误

“不幸的是,应用程序已停止”,我在程序中未发现任何语法错误,请帮助我

Conway's Game of Life 帮助我理解这个意外的输出

无法理解波纹管util方法,谁可以帮助我进行解释?

有人可以帮助我理解 Postgres 中的歧义吗?

任何人都可以帮助我理解下面代码中的问题吗?

Rails/Sidekiq:帮助我理解`initializers/sidekiq.rb` 示例中的重复

我想在指令中调用我的 API 并在我需要的地方使用指令。任何人都可以帮助我。请罚款我的例子

请在这个嵌套的for循环unix中帮助我