【问题标题】:Unable to update item on dynamoDb with aws-sdk on node.js无法使用 node.js 上的 aws-sdk 更新 dynamoDb 上的项目
【发布时间】:2020-06-03 20:10:55
【问题描述】:

我正在尝试更新我的用户表上的项目。 email是我的HASH键,id是我的RANGE

{
  "accessToken": {
    "M": {
      "expirationDate": {
        "N": "1622715427"
      },
      "token": {
        "S": "dummy-auth-accessToken-xxx"
      }
    }
  },
  "email": {
    "S": "xxx@toto.fr"
  },
  "firstName": {
    "S": "Xxx"
  },
  "id": {
    "S": "2"
  },
  "lastName": {
    "S": "Yyyy"
  },
  "password": {
    "S": "tataToto"
  },
  "refreshToken": {
    "M": {
      "expirationDate": {
        "N": "1622715427"
      },
      "token": {
        "S": "dummy-auth-refreshToken-xxx"
      }
    }
  },
  "username": {
    "S": "XxxY"
  }
}

我想更新访问和刷新令牌,所以我这样做:

const dynamoDb = new AWS.DynamoDB.DocumentClient();

const params = {
          TableName: 'Users',
          Key: { email: 'xxx@toto.fr' },
          UpdateExpression: 'set #at1 = :1, #at2 = :2, #at3 = :3, #at4 = :4',
          ExpressionAttributeNames: {
            '#at1': 'accessToken.token',
            '#at2': 'refreshToken.token',
            '#at3': 'accessToken.expirationDate',
            '#at4': 'refreshToken.expirationDate'
          },
          ExpressionAttributeValues: {
            ':1': 'new-dummy-auth-accessToken',
            ':2': 'new-dummy-auth-refreshToken',
            ':3': 1234567,
            ':4': 123456787654
          },
          ReturnValues: 'UPDATED_NEW'
        }

dynamoDb.update(params, (err, data) => {})

但我得到了:

Unable to update item. Error JSON: {
  "message": "The provided key element does not match the schema",
  "code": "ValidationException",
  "time": "2020-06-03T11:37:57.931Z",
  "requestId": "PDTS2SDOEIOPMAO4VHGU6QM21JVV4KQNSO5AEMVJF66Q9ASUAAJG",
  "statusCode": 400,
  "retryable": false,
  "retryDelay": 27.556977097280456
}

请问我做错了什么?

【问题讨论】:

  • 您的 DynamoDB 表有一个复合键(电子邮件 + id)。要识别单个项目,您需要同时提供两者。您只提供了密钥中的电子邮件。

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


【解决方案1】:

这是我的错...需要在 params 对象上添加 HASH AND RANGE 键

Key: { 
  id: "2"
  email: 'xxx@toto.fr'
}

我的表情不好,但我知道如何解决它:)

Ty 读 x)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-22
    相关资源
    最近更新 更多