“输入"dynamodb 中的语句 [英] "IN" statement in dynamodb

查看:16
本文介绍了“输入"dynamodb 中的语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户"表,这是一个示例:

I have a "Users" table, here is a sample :

{
    username:"haddox",
    formattedPhoneNumber:"676767676",
    verified: 0,
}

我希望检索其 formattedPhoneNumber 包含在电话号码数组(从我的联系人中检索)中的所有用户.我创建了一个二级索引,验证为 HASH,formattedPhoneNumber 为 RANGE.这是我的尝试:

My wish is to retrieve all users whose formattedPhoneNumber is contained in an array of phone numbers (retrieved from my contacts). I created a secondary index, with verified as HASH and formattedPhoneNumber as RANGE. Here is my try :

var params = {
    TableName: "Users",
    IndexName: "FormattedPhoneSecondaryIndex",
    KeyConditionExpression: "verified  = :v AND formattedPhone IN :n",
    ExpressionAttributeValues: {
        ":v":1,
        ":n": ["672053916", "642117296"]
    },
    ProjectionExpression: "username, formattedPhoneNumber"
};



dynamodb.query(params, function(err, data) {
    if (err)
        console.log(JSON.stringify(err, null, 2));
    else
        console.log(JSON.stringify(data, null, 2));
});

但我收到以下错误:Invalid KeyConditionExpression: Syntax error;令牌:":n",附近:"IN :n"",

IN 关键字有问题吗?也许还有另一种方法可以实现这一点?

Is there something wrong with the IN keyword ? Maybe there is another way to achieve this ?

推荐答案

KeyConditionExpression 不能使用IN"运算符(请参阅 http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#FilteringResults).在查询操作中使用 KeyConditions/KeyConditionExpression 的想法是更有效地从 DynamoDB 读取项目页面,因为具有相同哈希键但不同范围键的项目以连续且有序的顺序存储.IN 运算符需要提取某些页面的一小部分,这会降低 Query 操作的效率,因此在 KeyConditions 中是不允许的.您可能希望将其添加为 FilterExpression,这是一个方便的参数,可减少从 DynamoDB 返回的项目数量,但不会影响从 DynamoDB 读取数据的方式.

KeyConditionExpression's cannot use the "IN" operator (see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#FilteringResults). The idea with KeyConditions/KeyConditionExpression in a query operation is to more efficiently read pages of items from DynamoDB, since items with the same hash key but different range keys are stored contiguously and in sorted order. The IN operator would require extracting small portions of certain pages, which makes the Query operation less efficient, so it is not allowed in KeyConditions. You would want to add that as a FilterExpression instead, which is a convenience parameter to reduce the number of items returned from DynamoDB, but does not impact how the data is read from DynamoDB.

这篇关于“输入"dynamodb 中的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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