问题描述
这是我的代码,用于获取文本为做一顿晚餐"的所有元素.
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);
});
我收到此错误:
查询条件遗漏关键架构元素:todo_id
这个错误的原因是什么?如何避免?我的表中只有主键,没有排序键.
What is the reason for this error? How to avoid it? I have only primary key in my table, no sort key.
推荐答案
听起来 todo_id
是您的主键.您正在尝试对 todoName
进行查询.不能查询非关键字段.
It sounds like todo_id
is your primary key. You are trying to query on todoName
. You can't query on non-key fields.
您要么需要运行 scan
而不是 query
,或者将查询更改为使用 todo_id
而不是 todoName
,或将您的表主键更改为 todoName
,或在 todoName
上添加全局二级索引.
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
.
这篇关于AWS DynamoDb 中“查询条件丢失关键架构元素"的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!