简体   繁体   English

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

[英]Please help me understand this error I get from DELETE method

I am trying to work with DELETE route functionality.我正在尝试使用 DELETE 路由功能。 What I am trying to do is get the id from req.params and use it to delete the document associated with that particular id .我要做的是从req.params获取id并使用它来删除与该特定id关联的文档。 I am sharing my code below that also the error that I am getting.我在下面分享我的代码,这也是我得到的错误。 Can someone please tell me why I am getting this error?有人可以告诉我为什么会收到此错误吗? I am using CosmosDb here.我在这里使用 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);
    }

})

THE ERROR错误

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

I have no idea what is error is, also Postman gives me something different.我不知道什么是错误,Postman 也给了我一些不同的东西。

POSTMAN ERROR POSTMAN 错误

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

Did you try to use below code instead?您是否尝试改用以下代码? Azure official sample here. Azure 官方样品在这里。

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

在此处输入图像描述

I test in my side and it worked.我在我身边测试,它奏效了。

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 请帮助我获取哈希密码 - Please help me get the hashed password Webpack 配置错误 - 请帮我纠正 - Webpack Configuration Error - please help me correct 当我编写 npm start 并收到此错误时,我的反应应用程序没有启动,任何人都可以帮助我,我是新来的反应。 我正在使用 Acode(Editor) 和 termux - My react app does not start when I write npm start and get this error can anyone please help me I am new to react. I am using Acode(Editor) and termux 如何获取我的 MERN 应用程序上的所有帖子? 请帮我 - How can i get all posts on my MERN App? Please Help me 在nestjs项目中运行dist文件时出错,请帮助我 - I got an error while running dist file in nestjs project, please help me 我在终端中有一个错误节点,你能帮我解决它吗 - I have an error Node in Terminal, can you help me please to fix it 我对 discord.js rpc 有错误? 有人可以帮帮我吗? - I have an error for discord.js rpc! Can someone please help me? 错误:发送后设置标头-帮助我了解原因? - Error: Setting header after it is sent - Help me understand why? 我正在尝试显示来自外部 api 的数据,如果有人可以帮助我解决代码中的问题 - i am trying to display data from an external api, if someone can please help me to fix the issue in my code 有人可以向我解释我在哪里可以从Google Cloud获得属性以连接到sql数据库吗? - Can someone please explain to me where do I get the properties to connect to an sql database from google cloud?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM