DynamoDB 更新错误 Invalid UpdateExpression:未定义表达式中使用的表达式属性值 [英] DynamoDB update error Invalid UpdateExpression: An expression attribute value used in expression is not defined

查看:30
本文介绍了DynamoDB 更新错误 Invalid UpdateExpression:未定义表达式中使用的表达式属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对 DynamoDB 表执行更新.

I am trying to perform an update on DynamoDB table.

代码是(Node.js):

The code is (Node.js):

    let params = {
        TableName: Organizations.Table,
        Key: {
            'ID': event.ID
        },
        UpdateExpression: 'SET #OrgName = :org, #Description = :desc',
        ExpressionAttributeNames: {
            '#OrgName': 'OrgName',
            '#Description': 'Description'
        },
        ExpressionAtributeValues: {
            ':org': event.OrgName,
            ':desc': event.Description
        },
        ReturnValues: 'UPDATED_NEW'
    };
    this.docClient.update(params, (err, data) => {
        if (err) {
            return cb(err);
        }
        return cb(null, data);
    });

事件对象具有所需的所有属性.

The event object has all the properties needed.

执行后出现错误:

Invalid UpdateExpression: 中使用的表达式属性值表达式未定义;属性值::desc

Invalid UpdateExpression: An expression attribute value used in expression is not defined; attribute value: :desc

我只是按照 DynamoDB 文档中的示例进行操作.当我更改设置值的顺序时,例如到 SET #Description = :desc, #OrgName = :org 我得到的错误是关于属性值 :org.我也尝试明确指定表达式属性值,没有帮助.

I just followed the examples from DynamoDB docs. When I change the order of set values, e.g. to SET #Description = :desc, #OrgName = :org the error I get will be about attribute value :org. I also tried to specify expression attribute values explicitly, didn't help.

我不明白出了什么问题.

I can't get what is wrong.

有人可以帮我吗?

推荐答案

ExpressionAtributeValues 中存在拼写错误(即t"缺失),导致了问题.

There is a spelling mistake in ExpressionAtributeValues (i.e. 't' missing) which is causing the problem.

请尝试以下操作.它应该可以工作.

Please try the below. It should work.

UpdateExpression : "SET #OrgName = :org, #Description = :desc",
    ExpressionAttributeNames: {
        '#OrgName' : 'OrgName',
        '#Description' : 'Description'
    },
    ExpressionAttributeValues: {':org' : 'new org value', 
        ':desc' : 'new desc value'          
    },
    ReturnValues: 'UPDATED_NEW'

这篇关于DynamoDB 更新错误 Invalid UpdateExpression:未定义表达式中使用的表达式属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆