I have an array of users id's and I want to get all users with that id from the dynamoDB table
Didn't find it in the documentation
any ideas?
DynamoDB supports two types of primary keys: Partition key: A simple primary key, composed of one attribute known as the partition key. Attributes in DynamoDB are similar in many ways to fields or columns in other database systems.
Using normal DynamoDB operations you're allowed to query either only one hash key per request (using GetItem or Query operations) or all hash keys at once (using the Scan operation).
The BatchGetItem operation returns the attributes of one or more items from one or more tables. You identify requested items by primary key. A single operation can retrieve up to 16 MB of data, which can contain as many as 100 items.
You can not query only using a Sort Key. You need to specify a partition key to perform query operations. Else, you need to create a global secondary index or perform a scan operation.
I ended up using batchGet, an operation of AWS.DynamoDB.DocumentClient
There's no support for multiple items with same key, so I have to define the key over and over again like this:
var dynamoConfig = {
sessionToken: process.env.AWS_SESSION_TOKEN,
region: process.env.AWS_REGION
};
var dynamodbDocClient = new AWS.DynamoDB.DocumentClient(dynamoConfig);
var params = {
RequestItems: {
tableName: {
Keys: [
{
id: 'user1Id'
},
{
id: 'user2Id'
},
{
id: 'user3Id'
}
]
}
}
}
dynamodbDocClient.batchGet(paramsForQueringFormerEvaluators, function(err, data) {
if (err) {
console.log('createEvaluation: get former evaluators: err: ', err);
return;
}
var users = data.Responses.tableName;
console.log('createEvaluation: get former evaluators: ', users);
});
You can use the BatchGetItem API for this.
Of course, I can't help you with any code snippet without knowing your table schema. But you can look at the documentation here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With