1
votes

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 ?

1

1 Answers

1
votes

You're trying to query for multiple different partition key's in a GSI. This can only be done by doing multiple individual queries (3 in the example). It's also possible with a GSI that multiple values would get returned for a single Partition key lookup, so it's better to query the partition key "itemId" individually.

See the following for reference: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html#DDB-Query-request-KeyConditionExpression