Here is my code to fetch all elements that has a text as 'Make a dinner'.
const params = {
TableName: 'todos',
KeyConditionExpression: 'todoName = :t',
ExpressionAttributeValues: { ':t': 'Make a dinner' }
};
db.scan(params, (err, data) => {
if (err)
console.log(err);
});
I get this error:
Query condition missed key schema element: todo_id
What is the reason for this error? How to avoid it? I have only primary key in my table, no sort key.
Optionally, you can provide a sort key attribute and use a comparison operator to refine the search results. Use the KeyConditionExpression parameter to provide a specific value for the partition key. The Query operation will return all of the items from the table or index with that partition key value.
DynamoDB supports two types of secondary indexes: Global secondary index — An index with a partition key and a sort key that can be different from those on the base table. A global secondary index is considered "global" because queries on the index can span all of the data in the base table, across all partitions.
It sounds like todo_id
is your primary key. You are trying to query on todoName
. You can't query on non-key fields.
You either need to run a scan
instead of a query
, or change your query to use todo_id
instead of todoName
, or change your table primary key to be todoName
, or add a global secondary index on todoName
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With