Complete the code to define a Global Secondary Index (GSI) with the partition key.
CreateTableRequest {
TableName: "Orders",
KeySchema: [
{ AttributeName: "OrderId", KeyType: "HASH" }
],
AttributeDefinitions: [
{ AttributeName: "OrderId", AttributeType: "S" },
{ AttributeName: "[1]", AttributeType: "S" }
],
GlobalSecondaryIndexes: [
{
IndexName: "StatusIndex",
KeySchema: [
{ AttributeName: "[1]", KeyType: "HASH" }
],
Projection: { ProjectionType: "ALL" }
}
]
}The GSI uses the attribute 'Status' as the partition key to enable queries by order status.
Complete the code to add a sort key to the GSI for sorting orders by date.
GlobalSecondaryIndexes: [
{
IndexName: "StatusDateIndex",
KeySchema: [
{ AttributeName: "Status", KeyType: "HASH" },
{ AttributeName: "[1]", KeyType: "RANGE" }
],
Projection: { ProjectionType: "ALL" }
}
]The sort key 'OrderDate' allows sorting orders by date within each status group.
Fix the error in the GSI projection type to include only specific attributes.
GlobalSecondaryIndexes: [
{
IndexName: "CustomerIndex",
KeySchema: [
{ AttributeName: "CustomerId", KeyType: "HASH" }
],
Projection: { ProjectionType: "[1]", NonKeyAttributes: ["OrderDate", "Status"] }
}
]The 'INCLUDE' projection type allows specifying non-key attributes to be projected into the index.
Fill both blanks to create a GSI that overloads the 'Status' attribute to store different types of data.
GlobalSecondaryIndexes: [
{
IndexName: "OverloadIndex",
KeySchema: [
{ AttributeName: "[1]", KeyType: "HASH" },
{ AttributeName: "[2]", KeyType: "RANGE" }
],
Projection: { ProjectionType: "ALL" }
}
]The 'Status' attribute is overloaded as the partition key, and 'Category' is used as the sort key to differentiate data types.
Fill all three blanks to write a DynamoDB query using the overloaded GSI to get items with a specific status and category.
const params = {
TableName: "Orders",
IndexName: "OverloadIndex",
KeyConditionExpression: "#S = :statusVal AND #C = :categoryVal",
ExpressionAttributeNames: {
"#S": "[1]",
"#C": "[2]"
},
ExpressionAttributeValues: {
":statusVal": { S: "shipped" },
":categoryVal": { S: "electronics" }
}
};The query uses 'Status' as the partition key and 'Category' as the sort key in the KeyConditionExpression and ExpressionAttributeNames.