I am using the AWS DynamoDB DocumentClient to query my DynamoDB tables. In my tables I have a property called "_id" that holds a unique ID for each entry. When I try to query for a record based on this ID, I end up receiving an error that says: "Invalid KeyConditionExpression: Syntax error; token: \"_\", near: \"_id\"". The code that makes this query is below.
function findById(id) {
//Build query
var params = {};
params.TableName = "recordDev";
params.IndexName = "_id";
params.KeyConditionExpression = '_id = :id';
params.ExpressionAttributeValues = {
':id': id
};
return DynamoDB
.query(params).promise()
.then(function(records) {
return records.Items[0];
})
.catch(function(error) {
return Promise.reject(error);
});
};
Is there something that I am missing with regards to using an "_" when building the query params for DynamoDB? I have tried looking around for similar errors, but have been unable to find any that are like my scenario.