我正在为删除操作创建一个快速API,成功删除项目后,我希望删除的项目显示为响应,该项目正在从表中删除,但API给出<从 CURL 命令运行时,strong>空对象 {} 作为响应,我遵循这些 docs from aws .
这是我的代码
router.delete('/delete/:id',function(req, res, next) {
const params = {
TableName: 'Notes',
Key: {
id: req.params.id,
},
};
dynamoDb.delete(params, function (error,data) {
if (error) {
console.log(error);
res.status(400).json({ error: 'Could not update user' });
}
res.status(200).json(data);
});
})
curl 命令
curl -H "Content-Type: application/json" -X DELETE xxxxxxxxxxxxxxx/dev/user/delete/alexdebrie2
最佳答案
DynamoDB documentation DeleteItem
操作清楚地解释了这一点:
In addition to deleting an item, you can also return the item's attribute values in the same operation, using the
ReturnValues
parameter.
因此,默认情况下,删除操作不会返回已删除项目的旧值。如果需要,您需要将 ReturnValues
选项传递给 DynamoDB 请求。我不熟悉您用来实现此目的的任何编程语言,但我希望您可以自己解决这个问题。
关于node.js - 为什么Amazon DynamoDB的Delete方法不返回删除的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68148953/