I'm working on a application that is using DynamoDB as the database. I have a table of users like:
{
id: 1, (Primary Key)
name: "Indranil"
}
Now my requirement is, I have the array if ids like : [1,5,8] and I want to load all the users using single query.
Now I'm using the id as keyConditionExpreassion in the query and I can fetch each user data one after another, but then it'll result in multiple queries.
let readparams = {
TableName : "user",
KeyConditionExpression: "# = :",
ExpressionAttributeNames:{
"#": "id"
},
ExpressionAttributeValues: {
":id":1
}
};
Then I saw there is an 'IN' operation in the expressions but that can't be used in the KeyConditionExpression, it can be used in FilterExpreassion but in filterExpression I can't use primary key. And moreover I can't pass only filter expression in the query I have to pass a key expression as well but in my case I don't have any other condition to check.
let readparams = {
TableName : "user",
FilterExpression: "id IN (:id1, :id2)",
ExpressionAttributeValues: {
":id1":1,
":id2":1
}
};
So eventually I've left with only option, to load all the data in the frontend and then filter those using ids in the frontend, but obviously that's not a good solution at all.
Can someone please point out what is the best solution here.