DynamoDB DeleteItem显然不起作用 - 没有给出错误

问题描述 投票:0回答:1

我正在使用put并且没有问题,但是当涉及到删除时,没有任何反应。这是我的代码:

async function resetUserIdDB(userId) {
  let params = {
    TableName: 'TableName',
    "Key": {
      "userId": {
        "S": userId.toString()
      }
    }
  };
  try {
    const dbResponse = await ddb.deleteItem(params).promise();
    console.log(`dbresponse has params of ${JSON.stringify(params)} and response of ${JSON.stringify(dbResponse)}`);
    if (dbResponse.Item) {
      console.log(`deleted row with userId of ${userId}`);
      return (dbResponse);
    }
  } catch (err) {
      console.log(`user reset failed with ${err}`);
    throw new Error(`failed to reset because of ${err}`);
  }
}

params看起来都很好,但我得到一个空的响应,没有错误,但也没有删除。我在所有其他的动力学行为中都使用相同的.promise()。

有任何想法吗?

javascript node.js amazon-dynamodb aws-sdk
1个回答
0
投票

当您删除Dynamodb中的元素并且没有任何反应时,表示找不到该键,因此请仔细检查您的密钥。

该表存在,否则您会有错误说

com.amazonaws.services.dynamodb.model.ResourceNotFoundException:找不到请求的资源(服务:AmazonDynamoDB;状态代码:400;错误代码:ResourceNotFoundException;请求ID

例如,在表中删除:TABLEXAMPLE键:{id: "client", sortingKey: "TTN-BPLAN-7129-6114"}

检查id是否存在且是否正确,排序键是否存在且是否正确

© www.soinside.com 2019 - 2024. All rights reserved.