Bird
0
0

Given this DynamoDB query code snippet, what will be the output if the table contains items with userId 'user1' and 'user2' only?

medium📝 Predict Output Q13 of 15
AWS - DynamoDB
Given this DynamoDB query code snippet, what will be the output if the table contains items with userId 'user1' and 'user2' only?
const params = {
  TableName: 'Users',
  KeyConditionExpression: 'userId = :uid',
  ExpressionAttributeValues: { ':uid': 'user1' }
};
const result = await dynamoDBClient.query(params);
console.log(result.Items);
A[{ userId: 'user2', name: 'Bob' }]
B[]
C[{ userId: 'user1', name: 'Alice' }]
DError: Missing Key
Step-by-Step Solution
Solution:
  1. Step 1: Understand the query parameters

    The query searches for items where userId equals 'user1'.
  2. Step 2: Match items in the table

    Since the table has 'user1' and 'user2', only the item with 'user1' matches and is returned.
  3. Final Answer:

    [{ userId: 'user1', name: 'Alice' }] -> Option C
  4. Quick Check:

    Query filters by key condition, returns matching items [OK]
Quick Trick: Query returns items matching key condition [OK]
Common Mistakes:
  • Expecting all items returned
  • Confusing query with scan
  • Thinking query returns error without full key

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes