【发布时间】:2018-11-28 22:27:33
【问题描述】:
我正在尝试使用过滤表达式在 GSI 中执行查询,但 AWS 一直告诉我找不到表达式。 查询如下:
var tableQuery = {
TableName: "posts",
KeyConditionExpression: "#wy = :wkYr",
FilterExpression: "#ac = :isAct",
IndexName: "weekYear-date-index",
ScanIndexForward: false,
Limit: 50,
ExpressionAttributeNames: {
"#wy": "weekYear",
"#ac": "isActive"
},
ExpressionAttributeValues: {
":wkYr": cWeekYear,
":isAct": {BOOL: true}
}
};
以及显示的错误:
An expression attribute value used in expression is not defined; attribute value: :isAct
我一直在尝试不同的方法,但似乎没有任何效果,有什么想法吗?
当前查询的控制台日志:
{
"TableName": "posts",
"KeyConditionExpression": "#wy = :wkYr",
"FilterExpression": "#ac = :isAct",
"IndexName": "weekYear-date-index",
"ScanIndexForward": false,
"Limit": 50,
"ExpressionAttributeNames": {
"#wy": "weekYear",
"#ac": "isActive"
},
"ExpressionAttributeValues": {
":wkYr": 2040,
":isAct": {
"BOOL": true
}
}
}
【问题讨论】:
-
您使用的是DocumentClient 吗?如果不是,那么问题可能是属性值未定义为布尔值。
-
您是说要这样做吗:
":isAct": {BOOL: true},是的,我正在使用它进行查询:var dynamodb = new AWS.DynamoDB.DocumentClient(); -
是的,如果您使用的是 AWS.DynamoDB.DocumentClient,那么您在问题帖子中的用法是正确的,只是想澄清一下。
-
好吧,我真的不明白为什么会这样,因为所有的例子都是这样的,真的不知道发生了什么
-
我已经编辑了代码
标签: node.js amazon-web-services amazon-dynamodb