[英]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.