属性名称是DynamoDB中的保留关键字

时间:2018-04-30 08:12:54

标签: javascript html amazon-web-services amazon-dynamodb

从DynamoDB读取值时,我收到的错误是列名是保留关键字。我正在尝试读取名为“Status”的列的值。

我的剧本:

<script>
    AWS.config.update({
      region: "us-west-2",
      endpoint: 'https://dynamodb.us-west-2.amazonaws.com',
      accessKeyId: "Fakeaccesskey",
      secretAccessKey: "Fakesecretkey"
    });

    var docClient = new AWS.DynamoDB.DocumentClient();

    function readItembedonestatus() {
        var table = "TA_Latest_Log";
        var GWID = "BB00000001";
        var ID = "AA00000013";

        var params = {
            TableName: table,
            Key:{
                "GWID": GWID,
                "ID": ID
            },
               "ProjectionExpression": "#node_status"
               "ExpressionAttributeNames": "#node_status": "Status"
        };
        docClient.get(params, function(err, data) {
            if (err) {
                document.getElementById('bedonestatus').innerHTML = "Unable to read item: " + "\n" + JSON.stringify(err, undefined, 2);
            } else {
                document.getElementById('bedonestatus').innerHTML = data.Item.#node_status + "&deg;";

            }
        });
    }

</script>

我添加了ExpressionAttributeNames,但是,我无法让它工作。上面的脚本什么都不返回。

2 个答案:

答案 0 :(得分:0)

<script>
    AWS.config.update({
      region: "us-west-2",
      endpoint: 'https://dynamodb.us-west-2.amazonaws.com',
      accessKeyId: "Fakeaccesskey",
      secretAccessKey: "Fakesecretkey"
    });

    var docClient = new AWS.DynamoDB.DocumentClient();

    function readItembedonestatus() {
        var table = "TA_Latest_Log";
        var GWID = "BB00000001";
        var ID = "AA00000013";

        var params = {
            TableName: table,
            Key:{
                "GWID": GWID,
                "ID": ID
            },
            ExpressionAttributeNames: {"#node_status":"Status"},
            ProjectionExpression: "#node_status"
        };
        docClient.get(params, function(err, data) {
            if (err) {
                document.getElementById('bedonestatus').innerHTML = "Unable to read item: " + "\n" + JSON.stringify(err, undefined, 2);
            } else {
                document.getElementById('bedonestatus').innerHTML = data.Item.#node_status + "&deg;";

            }
        });
    }

</script>

ExpressionAttributeNames必须是地图。你在params列表中遗漏了一个逗号..

答案 1 :(得分:0)

@Stu以下查询有效,但这是因为它没有保留关键字(BatV)。

Program type already present: okhttp3.Call$Factory
Message{kind=ERROR, text=Program type already present: okhttp3.Call$Factory, sources=[Unknown source file], tool name=Optional.of(D8)}

这是亚马逊关于保留关键字的文档:https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html

我非常感谢您的时间和帮助。