I have a dynamo DB table (id(pk),name(sk),email,date,itemId(number)) and GSI on (itemId pk, date(sk) trying to query for an array of itemIds [1,2,3,4] but getting error using the IN statement in KeyExperssionValue when doing
aws.DocClient.query
const IdsArrat = [1,2,3,4,5];
const query: {
IndexName: 'accountId-createdAt-index',
KeyConditionExpression: 'itemId IN (:a1,:a2,:a3)',
ExpressionAttributeValues: {
{
':a1':1,
':a2':2,
.......
}
},
ScanIndexForward: false,
},
getting error using the IN statement in.
This it possible to query for multiple values on GSI in dynamoDb ?
It's not possible to have a IN
and join multiple values in a query , but it's possible to use BatchGetItem
to request multiple queries that are solved in parallel . This is actually very close to the IN
solution you want.
This solution is only working to query the table not the GSI index (thank you Monish Chhadwa !)
The result will be a list of the elements in the table.
There are limits in the number of queries in the size of the result set < 16 MB and the number of queries < 100.
Please check this document for details : https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchGetItem.html
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