0

I have users table, users have user_id field.

I need to get all the user details with given list, like ["1234","3456"].

There is no contain like queries in Boto3.

I'm using

response = table.scan(FilterExpression=Attr('user_id').is_in(["1234","3456"]))

But I'm not getting the expected results.

Correct me If I missed anything.

2
  • try to use in(["1234","3456"]) instead of is_in. Commented Dec 19, 2019 at 12:38
  • In Boto3 we dont have any option like "in" Commented Dec 19, 2019 at 12:54

1 Answer 1

1

One question that you need to answer is: user_id is your DynamoDB Hash/Partition Key? If it is, then the operation that you are looking for is: BatchGetItem. You can see how it works here.

If user_id is not your Partition/Hash Key, a first (and wrong) solution would be to scan the entire table and filter its data (a very expensive method that should be avoided at all costs). A second, more efficient solution would be to create a global index (GSI) using user_id as Hash/Partition Key and project the data to be returned in the index. You can learn more about GSI's 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.