I have a DynamoDB table that contains primary key : userID, sort key : sessionID and another column which is named examID.
i would like to return a list that returns all records that have the userID and examID sent by me. Here is my code:
export const main = handler(async (event, context) => {
const data = JSON.parse(event.body);
const params = {
TableName: process.env.tableNameExamResults,
KeyConditionExpression: "userId = :userId and examId = :examId",
ExpressionAttributeValues: {
":userId": event.requestContext.identity.cognitoIdentityId,
":examId": data.examId
}
};
const result = await dynamoDb.query(params);
return result.Items;
});
this is the error that i get: { "statusCode": 500, "body": "{"error":"Query condition missed key schema element: sessionId"}",
...
I think that maybe i should include a Filter Expression or not sure if i have to recreate the DB with an index.
Any help is appreciated. thank you