3

I'm trying to get a list of entries from DynamoDb using FilterExpression. I'd like to return value if at least one of the statements are TRUE. But for some reason looks like AND is a default conditional operator and my result is empty. How to change default conditional operation to OR in NodeJS?

            params = {
                TableName: '......',
                IndexName : 'user_id-index',
                KeyConditionExpression: 'user_id = :user_id',
                FilterExpression: 'contains (email, :key) OR contains (name, :key)',
                ExpressionAttributeValues: {
                    ":user_id": userId,
                    ":key": item_to_search
                }
            };

1 Answer 1

5

Your problem is that NAME is a reserved word in DynamoDB. So, you'll have to use ExpressionAttributeNames for that:

params = {
  TableName: '......',
  IndexName: "user_id-index",
  KeyConditionExpression: "user_id = :user_id",
  FilterExpression: "contains (email, :key) OR contains (#name, :key)",
  ExpressionAttributeNames: {
    "#name": "name"
  }
  ExpressionAttributeValues: {
    ":user_id": userId,
    ":key": item_to_search
  }
};
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.