node.js - 为什么Amazon DynamoDB的Delete方法不返回删除的结果?

标签 node.js amazon-web-services express amazon-dynamodb

我正在为删除操作创建一个快速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/

相关文章:

amazon-s3 - 学习 Amazon Web Services 的好书

javascript - 如何在 React JS 中加载页面时自动调用函数?(2020 年)

node.js - 如何在命令行上将分层配置值传递给 nconf?

MySQL 查询不会提取 Node.js 中的值

javascript - 我该如何删除 JSON 中的特定字段以进行测试,然后在另一个测试中重新加载 JSON,而不缓存删除内容?

javascript - 数组过滤器(mongodb)在我的nodejs后端不起作用

node.js - NodeJS + MongoDB : Getting data from collection with findOne ()

node.js - ffmpeg jpeg 流到 webm 仅创建具有 1 帧(快照)或空 .webm 文件(mjpeg)的文件 .webm

node.js - Node 集群 worker 内存使用情况

amazon-web-services - 如何从 Amazon Elastic Transcoder 获取视频时长?