Reputation: 414
I'm hoping this is something really simple that I've miss understood as I'm new to both DynamoDb and nodeJs.
I have a table that has id, siteId.
These are being used to create a Global Secondary Index named IdxSiteId.
I need to be able to grab some of the other Item's values (not shown in screenshot) using the siteId. Reading things the best option is to use Query rather than GetItemBatch or Scan. Through trail and error got to this point.
const getWarnings = async (siteId) => {
const params = {
TableName: process.env.WARNINGS_TABLE_NAME,
IndexName: 'IdxSiteId',
KeyConditionExpression: 'SiteId = :var_siteId',
ExpressionAttributeValues: {
':var_siteId': siteId
},
ProjectionExpression: 'id, endTime, startTime, warningSubType',
ScanIndexForward: false
};
return new DynamoDB.DocumentClient().query(params).promise();
};
While this is the closest it has appeared to working I'm getting the following error Error retrieving current warnings ValidationException: Query condition missed key schema element: siteId
and looking at the examples online I don't know what I'm doing wrong at this point.
As I said I'm sure this is super simple, but I could really do with a pointer.
Upvotes: 0
Views: 1015
Reputation: 201103
Field names are case sensitive. Your GSI partition key is siteId
. Your query is SiteId = :var_siteId
. It should be siteId = :var_siteId
.
Upvotes: 2