Complete the code to query items from a DynamoDB table using the primary key.
response = table.query(KeyConditionExpression=Key('[1]').eq('123'))
The KeyConditionExpression requires the primary key attribute name. Here, 'UserId' is the partition key used to query items.
Complete the code to sort query results in descending order.
response = table.query(KeyConditionExpression=Key('UserId').eq('123'), [1]=False)
The ScanIndexForward parameter controls the order of query results. Setting it to False returns results in descending order.
Fix the error in the query to use the correct key condition syntax.
response = table.query(KeyConditionExpression=Key('UserId').[1]('123'))
The eq method is used to specify equality in the key condition expression for querying by primary key.
Fill both blanks to query items with a partition key and sort key condition.
response = table.query(KeyConditionExpression=Key('[1]').eq('123') & Key('[2]').[3]('2023-01-01'))
The query uses the partition key 'UserId' with equality and the sort key 'OrderDate' with the begins_with function to filter items starting with a date prefix.
Fill all three blanks to create a query that filters results and projects specific attributes.
response = table.query(KeyConditionExpression=Key('[1]').eq('123'), FilterExpression=Attr('[2]').[3]('active'), ProjectionExpression='UserId, [2]')
The query filters items where the 'Status' attribute equals 'active' and projects only 'UserId' and 'Status' attributes in the result.