Bird
0
0

You implemented pagination in DynamoDB SDK but the query always returns the first page repeatedly. What is the most probable cause?

medium📝 Debug Q6 of 15
DynamoDB - with AWS SDK
You implemented pagination in DynamoDB SDK but the query always returns the first page repeatedly. What is the most probable cause?
let params = { TableName: 'Orders', Limit: 3 };
let data = await dynamoDbClient.query(params);
params.ExclusiveStartKey = data.LastEvaluatedKey;
data = await dynamoDbClient.query(params);
console.log(data.Items);
ANot updating params.ExclusiveStartKey before the second query
BUsing query instead of scan for pagination
CAssigning ExclusiveStartKey after the first query instead of before
DSetting Limit too low causing repeated first page
Step-by-Step Solution
Solution:
  1. Step 1: Analyze code flow

    The code runs the first query, then sets ExclusiveStartKey from LastEvaluatedKey, then runs the second query.
  2. Step 2: Identify timing of setting ExclusiveStartKey

    Since ExclusiveStartKey is set after the first query, the second query uses the correct key.
  3. Step 3: Check if the key is valid

    If LastEvaluatedKey is undefined or null, setting ExclusiveStartKey to it causes the second query to fetch the first page again.
  4. Step 4: Most probable mistake

    Not checking if LastEvaluatedKey exists before assigning it causes repeated first page.
  5. Final Answer:

    Assigning ExclusiveStartKey after the first query without validation -> Option C
  6. Quick Check:

    Check if LastEvaluatedKey is null before using [OK]
Quick Trick: Validate LastEvaluatedKey before setting ExclusiveStartKey [OK]
Common Mistakes:
MISTAKES
  • Ignoring null LastEvaluatedKey causing repeated pages
  • Confusing query and scan for pagination issues

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes