Complete the code to specify the primary key attribute name in a DynamoDB query.
KeyConditionExpression = '#pk = :[1]'
The primary key attribute name used in the query must match the table's partition key, commonly named 'userId' in examples.
Complete the code to specify the index name for a DynamoDB query to support a specific access pattern.
IndexName='[1]'
Global Secondary Indexes (GSIs) are named like 'GSI1' to support alternate access patterns.
Fix the error in the DynamoDB query expression to correctly filter items by sort key.
KeyConditionExpression = '#pk = :userId AND [1] = :sortKeyVal'
The sort key attribute is often abbreviated as 'sk' in DynamoDB table designs to support access patterns.
Fill both blanks to create a DynamoDB query that uses a partition key and a begins_with condition on the sort key.
KeyConditionExpression = '#pk = :userId AND begins_with(#[1], :[2])'
The sort key attribute is 'sk', and the begins_with function uses a prefix string to filter items starting with that prefix.
Fill all three blanks to build a DynamoDB query that filters items by partition key, sort key greater than a value, and uses a specific index.
response = table.query(IndexName='[1]', KeyConditionExpression='#pk = :userId AND #sk [2] :sortVal', ExpressionAttributeNames={'#pk': 'userId', '#sk': '[3]'}, ExpressionAttributeValues={':userId': '123', ':sortVal': '2023-01-01'})
The query uses the global secondary index 'GSI2', the greater than operator '>' for filtering sort keys, and the sort key attribute 'createdAt'.