Bird
0
0

Given the following code snippet using DynamoDB Document Client, what will be the output if the item exists?

medium📝 query result Q13 of 15
DynamoDB - with AWS SDK
Given the following code snippet using DynamoDB Document Client, what will be the output if the item exists?
const params = { TableName: "Users", Key: { userId: "123" } };
const command = new GetCommand(params);
const data = await docClient.send(command);
console.log(data.Item);
AAn object representing the user with userId '123', e.g., { userId: '123', name: 'Alice' }
BA string containing the userId '123'
CAn error because GetCommand is not supported by Document Client
DUndefined, because data.Item is not returned
Step-by-Step Solution
Solution:
  1. Step 1: Understand GetCommand with Document Client

    GetCommand returns an object with an Item property containing the requested item if it exists.
  2. Step 2: Analyze console.log output

    Logging data.Item prints the full object stored for userId '123', not just a string or undefined.
  3. Final Answer:

    An object representing the user with userId '123', e.g., { userId: '123', name: 'Alice' } -> Option A
  4. Quick Check:

    GetCommand returns item object = B [OK]
Quick Trick: GetCommand returns full item object in data.Item [OK]
Common Mistakes:
MISTAKES
  • Expecting only the key value as output
  • Thinking GetCommand is unsupported
  • Assuming data.Item is undefined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes