0

I have an array of usernames and I want to retrieve from a DynamoDB table all the items that contains usernames that exist in the array.

For Example: if my array is:

["Foo","Bar"]

and my table is:

username | attribute1 | attribute2 Foo | Value 1 | Value 2 Min | value1 | value2 Bar | value 1 | value 2

Then i want to get the first item and the last item.

I read the documentation for the scan operation but it doesn't seem to support this type of request.

Is what I'm asking for possible or am i going to have to iterate over my usernames array and retrieve items for each of them separately?

2
  • username is the hash key of the table? Commented May 19, 2017 at 9:34
  • @notionquest Yes Commented May 19, 2017 at 13:10

2 Answers 2

1

Here is the batch get example. Please note that you may need to execute the batch API until UnprocessedKeys is null.

Batch Get API

var params = {
    "RequestItems" : {
        "yourtablename" : {
            "Keys" : [ {
                "username" : "Foo"              
            },{
                "username" : "Bar"              
            } ],
        }
    },
    "ReturnConsumedCapacity" : "TOTAL"
};

docClient.batchGet(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));
    }
});
Sign up to request clarification or add additional context in comments.

Comments

0

You may want to use the Batch Get Item API if user name is the Hash Key of the table.

The Batch Get Item API allows you to retrieve multiple items from the DynamoDB table based, provided the keys you provide in the request are part of the HashKey(+RangeKey) or a Global Secondary Index (HashKey (+RangeKey)).

1 Comment

Can you show me an example of how to do that? The username is my hash key but there's no range key.

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.