Bird
0
0

You want to update a DynamoDB item to increment a numeric attribute "score" by 5 using SDK helpers. Which code snippet correctly builds the UpdateExpression and attribute values?

hard🚀 Application Q15 of 15
DynamoDB - with AWS SDK
You want to update a DynamoDB item to increment a numeric attribute "score" by 5 using SDK helpers. Which code snippet correctly builds the UpdateExpression and attribute values?
AUpdateExpression: "set score = score + :inc", ExpressionAttributeValues: { ":inc": 5 }
BUpdateExpression: "add score :inc", ExpressionAttributeValues: { ":inc": 5 }
CUpdateExpression: "set #s = #s + :inc", ExpressionAttributeNames: { "#s": "score" }, ExpressionAttributeValues: { ":inc": 5 }
DUpdateExpression: "increment score by 5"
Step-by-Step Solution
Solution:
  1. Step 1: Use placeholders for attribute names

    Since "score" is an attribute name, use ExpressionAttributeNames with #s placeholder.
  2. Step 2: Build UpdateExpression correctly

    Use "set #s = #s + :inc" to increment score by value in :inc.
  3. Step 3: Provide ExpressionAttributeValues

    Set ":inc" to 5 to add 5 to score.
  4. Final Answer:

    UpdateExpression: "set #s = #s + :inc", ExpressionAttributeNames: { "#s": "score" }, ExpressionAttributeValues: { ":inc": 5 } -> Option C
  5. Quick Check:

    Use placeholders for names and values [OK]
Quick Trick: Use # for names and : for values in expressions [OK]
Common Mistakes:
MISTAKES
  • Not using ExpressionAttributeNames for attribute names
  • Using unsupported syntax like 'increment score by 5'
  • Using 'add' without placeholders

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes