0
0
DynamoDBquery~20 mins

Document client abstraction in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Document Client Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this DynamoDB DocumentClient get operation?
Consider a DynamoDB table named Users with a primary key userId. The table contains an item with userId = '123' and name = 'Alice'. What will be the output of the following DocumentClient get call?
DynamoDB
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient();

const params = {
  TableName: 'Users',
  Key: { userId: '123' }
};

docClient.get(params).promise().then(data => console.log(data));
A{"Item": {"userId": "123", "name": "Alice"}}
B{"Items": [{"userId": "123", "name": "Alice"}]}
C{"userId": "123", "name": "Alice"}
D{"Count": 1, "Items": [{"userId": "123", "name": "Alice"}]}
Attempts:
2 left
💡 Hint
The get operation returns a single item inside the 'Item' property.
📝 Syntax
intermediate
2:00remaining
Which option correctly updates an attribute using DocumentClient update method?
You want to update the attribute age to 30 for the item with userId = '123' in the Users table. Which of the following params objects is syntactically correct for DocumentClient update?
A{ TableName: 'Users', Key: { userId: '123' }, UpdateExpression: 'set age = :a', ExpressionAttributeValues: { ':a': '30' }, ReturnValues: 'UPDATED_NEW' }
B{ TableName: 'Users', Key: { userId: '123' }, UpdateExpression: 'set age = a', ExpressionAttributeValues: { ':a': 30 }, ReturnValues: 'UPDATED_NEW' }
C{ TableName: 'Users', Key: { userId: '123' }, UpdateExpression: 'set age = :a', ExpressionAttributeValues: { 'a': 30 }, ReturnValues: 'UPDATED_NEW' }
D{ TableName: 'Users', Key: { userId: '123' }, UpdateExpression: 'set age = :a', ExpressionAttributeValues: { ':a': 30 }, ReturnValues: 'UPDATED_NEW' }
Attempts:
2 left
💡 Hint
ExpressionAttributeValues keys must start with a colon and match placeholders in UpdateExpression.
optimization
advanced
2:00remaining
How to efficiently retrieve multiple items by keys using DocumentClient?
You need to get multiple items from the Users table by their userId keys: '123', '456', and '789'. Which approach is the most efficient and correct using DocumentClient?
AUse query with KeyConditionExpression userId IN ('123', '456', '789')
BUse batchGet with RequestItems: { Users: { Keys: [ { userId: '123' }, { userId: '456' }, { userId: '789' } ] } }
CUse scan with FilterExpression to filter userId IN ('123', '456', '789')
DCall get three times sequentially with each userId key
Attempts:
2 left
💡 Hint
BatchGet allows retrieving multiple items by keys in one request.
🔧 Debug
advanced
2:00remaining
Why does this DocumentClient put operation fail with a ValidationException?
You try to put an item into the Users table with this code but get a ValidationException error. What is the cause?
DynamoDB
const params = {
  TableName: 'Users',
  Item: {
    userId: 123,
    name: 'Bob'
  }
};

await docClient.put(params).promise();
AThe userId should be a string, not a number, because the table's primary key is a string.
BThe TableName is case sensitive and should be 'users' instead of 'Users'.
CThe Item property should be named Attributes instead of Item.
DThe put method requires a ConditionExpression to succeed.
Attempts:
2 left
💡 Hint
Check the data type of the primary key value against the table schema.
🧠 Conceptual
expert
2:00remaining
What is a key benefit of using DynamoDB DocumentClient abstraction?
Why do developers prefer using the DynamoDB DocumentClient abstraction over the low-level DynamoDB client?
AIt encrypts data automatically before sending to DynamoDB.
BIt provides built-in support for transactions without additional configuration.
CIt automatically converts JavaScript objects to DynamoDB attribute value format and back, simplifying code.
DIt allows querying tables without specifying keys or indexes.
Attempts:
2 left
💡 Hint
Think about how DocumentClient handles data types compared to the low-level client.