Complete the code to define a Global Secondary Index (GSI) with a partition key.
GlobalSecondaryIndexes: [{
IndexName: 'UserEmailIndex',
KeySchema: [{ AttributeName: [1], KeyType: 'HASH' }],
Projection: { ProjectionType: 'ALL' }
}]The partition key for the GSI is usually an attribute like 'email' to allow querying by email.
Complete the code to specify the projection type for a GSI that only includes specific attributes.
Projection: {
ProjectionType: [1],
NonKeyAttributes: ['name', 'age']
}'INCLUDE' projection type allows you to specify which non-key attributes to include in the index.
Fix the error in the GSI KeySchema definition by choosing the correct key type for the sort key.
KeySchema: [
{ AttributeName: 'email', KeyType: 'HASH' },
{ AttributeName: 'signupDate', KeyType: [1] }
]The sort key in DynamoDB is specified with KeyType 'RANGE'.
Fill both blanks to define a GSI with a partition key and a sort key.
GlobalSecondaryIndexes: [{
IndexName: 'OrderIndex',
KeySchema: [
{ AttributeName: [1], KeyType: 'HASH' },
{ AttributeName: [2], KeyType: 'RANGE' }
],
Projection: { ProjectionType: 'ALL' }
}]The partition key is 'customerId' to group orders by customer, and the sort key is 'orderDate' to sort orders by date.
Fill all three blanks to create a GSI with a partition key, sort key, and projection type.
GlobalSecondaryIndexes: [{
IndexName: 'ProductIndex',
KeySchema: [
{ AttributeName: [1], KeyType: 'HASH' },
{ AttributeName: [2], KeyType: 'RANGE' }
],
Projection: { ProjectionType: [3] }
}]The GSI uses 'category' as partition key, 'price' as sort key, and projects all attributes.