使用 Lambda (node.js) 进行 DynamoDB 查询:不支持查询键条件 [英] DynamoDB query with Lambda (node.js): Query key condition not supported

查看:29
本文介绍了使用 Lambda (node.js) 进行 DynamoDB 查询:不支持查询键条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从 Lambda 函数查询我的 dynamoDB.我的表使用id"作为哈希键.我尝试了以下两个版本并收到了相应的错误消息.我做错了什么?

I try to query my dynamoDB from a Lambda function. My table uses "id" as the hash key. I tried both versions below and received the corresponding error messages. What am I doing wrong?

  var params = {
        TableName : "addresses",
        KeyConditionExpression: "id = :id AND city = :city",
        ExpressionAttributeValues: {
            ":id": "Austria",
            ":city": "Salzburg"
        }
    };

无法查询.错误: {"message": "不支持查询键条件",...}

Unable to query. Error: { "message": "Query key condition not supported",...}

var params = {
    TableName : "addresses",
    KeyConditionExpression: "city = :city",
    ExpressionAttributeValues: {
        ":city": "Salzburg"
    }
};

无法查询.错误: {"message": "查询条件错过关键架构元素:id",...}

Unable to query. Error: { "message": "Query condition missed key schema element: id",...}

我现在添加了二级索引,但仍然出现相同的错误:

I now added secondary indices, but still get the same errors:

推荐答案

如果你的哈希键是 'id' 那么你不能查询:

if your hash key is 'id' then you cant query by:

KeyConditionExpression: "id = :id AND city = :city"

或通过:

KeyConditionExpression: "city = :city"

您只能通过哈希和范围键查询dynamodb.

you can query dynamodb only by hash and range key.

所以您的查询应该始终包含哈希键 (id).如果您还想按城市"查询,则应将城市"作为范围键添加到 dynamodb 表(或本地二级索引)

so your query should contain always hash key (id). if you want to query by 'city' also, you should add 'city' as range key to dynamodb table (or local secondary index)

然后就可以用'id''city'查询记录了.

then you can query for a record with 'id' and 'city'.

更新:

如果要查询'city'

KeyConditionExpression: "city = :city"

那么你可以在表中添加全局二级索引.

then you can just add global secondary index to the table.

这篇关于使用 Lambda (node.js) 进行 DynamoDB 查询:不支持查询键条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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