Skip to content

Using begins_with attribute with lib-dynamodb #5317

Answered by jhughes982
jhughes982 asked this question in Q&A
Discussion options

You must be logged in to vote

Closed due to my mistake mixing up GetCommand and QueryCommand. You can indeed filter with begins_with using the V3 SDK when you use QueryCommand but not with GetCommand. Solution below:

  const command = new QueryCommand({
    TableName: TABLE_NAME,
    KeyConditionExpression: '#pk = :pk and begins_with(#sk, :sk)',
    ExpressionAttributeNames: {
      '#pk': 'pk',
      '#sk': 'sk',
    },
    ExpressionAttributeValues: {
      ':pk': userId,
      ':sk': 'user',
    },
  });

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by jhughes982
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant