Bird
0
0

This query code returns no items even though the table has matching data:

medium📝 Debug Q7 of 15
AWS - DynamoDB
This query code returns no items even though the table has matching data:
const params = {
  TableName: 'Employees',
  KeyConditionExpression: 'EmployeeId = :id',
  ExpressionAttributeValues: { ':id': 'E123' }
};
const data = await client.query(params);
console.log(data.Items.length);

What is the error?
ATableName is misspelled
BKeyConditionExpression syntax is incorrect
CQuery requires ScanIndexForward parameter
DExpressionAttributeValues values must be wrapped with DynamoDB types
Step-by-Step Solution
Solution:
  1. Step 1: Check ExpressionAttributeValues format

    Values must be wrapped with DynamoDB types like { S: 'E123' }.
  2. Step 2: Identify cause of no results

    Without type wrappers, the query does not match any items, returning zero results.
  3. Final Answer:

    ExpressionAttributeValues values must be wrapped with DynamoDB types -> Option D
  4. Quick Check:

    Query values need DynamoDB type wrappers [OK]
Quick Trick: Always wrap query values with DynamoDB types like { S: 'value' } [OK]
Common Mistakes:
MISTAKES
  • Using raw string instead of typed value
  • Assuming ScanIndexForward is required
  • Ignoring case sensitivity in keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes