Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the reason for 'Query condition missed key schema element' in AWS DynamoDb?

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.

like image 362
neo Avatar asked Sep 23 '18 16:09

neo


People also ask

What is KeyConditionExpression in DynamoDB?

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.

What is global secondary index DynamoDB?

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.


1 Answers

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.

like image 183
Mark B Avatar answered Oct 21 '22 12:10

Mark B