简体   繁体   中英

Unable to update item on dynamoDb with aws-sdk on node.js

I'm trying to update items on my Users table. email is my HASH key and id my 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"
  }
}

I would like to update access and refresh token, so i'm doing this:

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) => {})

but i got:

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
}

What I'm doing wrong please?

It's my bad... Need to add HASH AND RANGE key on params object

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

and my expressions is not good but i know how fix it:)

Ty to read x)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM