请帮助我理解我从 DELETE 方法中得到的这个错误
Please help me understand this error I get from DELETE method
我正在尝试使用删除路线功能。我想要做的是从 req.params
获取 id
并使用它来删除与特定 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'
}
}
我不知道错误是什么,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"}
您是否尝试改用以下代码? Azure official sample 在这里。
const docResponse = await container.item(id, partitionKey).delete();
我在身边测试过,效果很好。
我正在尝试使用删除路线功能。我想要做的是从 req.params
获取 id
并使用它来删除与特定 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'
}
}
我不知道错误是什么,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"}
您是否尝试改用以下代码? Azure official sample 在这里。
const docResponse = await container.item(id, partitionKey).delete();
我在身边测试过,效果很好。