Bird
0
0

You want to update a user's email in DynamoDB only if the user exists. Which operation and condition should you use?

hard📝 Best Practice Q15 of 15
AWS - DynamoDB
You want to update a user's email in DynamoDB only if the user exists. Which operation and condition should you use?
AUse <code>query</code> to find the user, then <code>put</code> to update
BUse <code>get</code> to check existence, then <code>put</code> to update
CUse <code>put</code> without any condition
DUse <code>put</code> with a condition expression checking attribute_exists(userId)
Step-by-Step Solution
Solution:
  1. Step 1: Understand conditional update

    To update only if the user exists, use put with a condition expression that checks for the user's existence.
  2. Step 2: Use attribute_exists condition

    The condition attribute_exists(userId) ensures the item exists before updating, preventing overwriting non-existing items.
  3. Final Answer:

    Use put with a condition expression checking attribute_exists(userId) -> Option D
  4. Quick Check:

    Conditional put prevents overwriting missing items [OK]
Quick Trick: Use put with condition attribute_exists() to update safely [OK]
Common Mistakes:
  • Using get then put causes race conditions
  • Using query unnecessarily for single item
  • Putting without condition overwrites blindly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes