AWS DynamoDB查询未按BOOL值进行过滤 [英] AWS DynamoDB query not filtering on BOOL value

查看:145
本文介绍了AWS DynamoDB查询未按BOOL值进行过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用GUI创建的用户表,给定了电子邮件的分区密钥,它是一个字符串。然后,我使用aws lambda来执行以下putItem:

I have a users table that was create with the GUI and given a partion key of email and it is a string. I then used aws lambda to do a putItem that had:

email (string) test@testing.com
deleted (BOOL) false

此方法很好。然后,我尝试使用以下参数使用lambda进行查询并进行查询:

This worked fine. I then tried to query it with lambda using the following params and query:

var params =
{
    TableName : 'Users', 
    KeyConditionExpression : 'email = :email',
    FilterExpression : 'deleted = :deleted',
    ExpressionAttributeValues :
    {
        ':email' : email,
        ':deleted':
        {
            BOOL: false
        }
    }
};

docClient.query(params, function(err, data)
{
    if (err) return fn(err);
    else
    {
        console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
    }
});

当我搜索email = test@testing.com并将其保留为假。如果删除删除的过滤器表达式,则会得到项返回,那么为什么BOOL = false无效,还是应该使用其他方法?

This always returns 0 items when I search for email = test@testing.com and leave the deleted as false. If I remove the filter expression of deleted I get an item return so why doesn't the BOOL = false work or should I use something else?

推荐答案

以下是用于过滤 BOOL 数据的代码。不需要像下面这样编码,因为DynamoDB将其解释为MAP数据类型内的BOOL值。

Here is the code to filter BOOL data. It is not required to code like below as DynamoDB interpret it as BOOL value inside MAP data type.

{ BOOL: false        }

更改为:-

':deleted' :  false

代码:-

var table = "users";

var params = {
    TableName : table,
    KeyConditionExpression : 'email = :email',
    FilterExpression: 'deleted = :deleted',
    ExpressionAttributeValues : {
        ':email' : 'abc@gmail.com',
        ':deleted' :  false
    }   
};

docClient.query(params, function(err, data) {
    if (err) {
        console.error("Unable to read item. Error JSON:", JSON.stringify(err,
                null, 2));
    } else {
        console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
    }
});

我的具有BOOL数据的DynamoDB项目:-

这篇关于AWS DynamoDB查询未按BOOL值进行过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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