Home > Software engineering >  how to do the update when my key is called key
how to do the update when my key is called key

Time:05-06

I have a problem with an update in dynamoDB , when performing the update in dyanamo it tells me that I cannot use the key keyword

"message": "Value provided in ExpressionAttributeNames unused in expressions: keys: {#keyid}", "code": "ValidationException", "time": "2022-05-06T00:24:03.502Z",

When using the ExpressionAttributeNames I must relate the key with a different name "Key" but in the table its id is called key and it generates the previous error when updating this my code.

function updateUser(key, sortkey, dateFiling) {

    try {

        let params = {
            TableName: env.getEnv(CTE.User),
            Key: { "#keyid": key , "sortkey": sortkey },
            UpdateExpression: "set dateFiling = :dateFiling",
            ExpressionAttributeNames: { '#keyid': 'key' },
            ExpressionAttributeValues: { ":dateFiling": dateFiling }
        };

        await db.updateItem(params);

        console.log(params); 
    }

    catch (error) { 

        console.log('Error  in updateUser %j:', error);
   }
}

my doubt is exactly with the ExpressionAttributeNames since it does not take the keyid envelope to refer to the key and not have a problem with the use of the reserved word. Can somebody help me. please

CodePudding user response:

The Key argument accepts reserved keywords:

Key: { "key": key , "sortkey": sortkey },

Reserved keywords are no-nos is expressions like UpdateExpression. DynamoDB is complaining that you are not using ExpressionAttributeNames in a expression, which is true. Remove it.

  • Related