Querying by HASH key only from GSI
How is it possible to fetch only by hash-key from a GSI?
E.g. I have this table
{
TableName: 'contact',
KeySchema: [
{ AttributeName: 'id', KeyType: 'HASH'},
],
AttributeDefinitions: [
{ AttributeName: 'id', AttributeType: 'S' },
{ AttributeName: 'account', AttributeType: 'S' },
],
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 3,
},
GlobalSecondaryIndexes: [
{
IndexName: 'accountIndex',
KeySchema: [
{ AttributeName: 'account', KeyType: 'HASH' },
],
Projection: {
ProjectionType: 'ALL',
},
ProvisionedThroughput: {
ReadCapacityUnits: 3,
WriteCapacityUnits: 3,
},
},
],
}
And I would like to execute this query with vogels:
docClient.query({
TableName: 'contact',
IndexName: 'accountIndex',
KeyConditionExpression: 'account = :account',
ExpressionAttributeValues: { ':account': 'myaccount' },
}, callback);
Perhaps something like this: ?
Contact
.query('myaccount')
.usingIndex('accountIndex')
.exec(callback);
You know that there is a documentation about this :-) There is also expression API that you may use if you don't like this method.
@set-killer Thanks for the suggestion. I tried it already, and it responds with error MissingRequiredParameter: Missing required key 'Key' in params. All the examples in the documentation use both hash and range key for the queries, which made me question if the above is even possible.
The problem remains.
@set-killer gave you the answer about how using an Index. Your error means you didn't pass the id in 1st parameter
Can you paste you query corrected please ?