7

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) [email protected]
deleted (BOOL) false

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));
    }
});

This always returns 0 items when I search for email = [email protected] 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?

9
  • Can you show your DynamoDB sample data? I am wondering whether you have deleted field with BOOL data type. Commented Nov 7, 2016 at 9:39
  • Yes I do. How do you check in the dynamodb gui what datatypes the items are? Commented Nov 7, 2016 at 9:42
  • The filter in the gui appears to only allow queries of string, binary or number Commented Nov 7, 2016 at 9:43
  • The attribute should be prefixed with the type. Commented Nov 7, 2016 at 9:44
  • Can you filter by email and show the screen shot of the item? Commented Nov 7, 2016 at 9:45

1 Answer 1

15

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        }

Change to:-

':deleted' :  false

Code:-

var table = "users";

var params = {
    TableName : table,
    KeyConditionExpression : 'email = :email',
    FilterExpression: 'deleted = :deleted',
    ExpressionAttributeValues : {
        ':email' : '[email protected]',
        ':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));
    }
});

My DynamoDB item which has BOOL data:-

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.